使用MYSQL数据库,创建一个mytest数据库,创建一个person表,字段有
id,name,password,sex,email 都设置为nvarchar类型。方便测试。
在NB中,新建一个JAVA项目
选择JAVA应用程序
起一个过程名字名字:ht01,选定存放目录后,别的不用修改,点完成。
在项目页中的ht01树中,包里,引入Hibernate包,和MYSQL-JDBC连接包.
在项目中,新建"Hibernate配置文件",产生一个hibernate.cfg.xml文件,在项目下,空包里。
内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mytest</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
</session-factory>
</hibernate-configuratio