说明:本实例使用的是mysql数据库
1、下载hibaernate开发包:http://hibernate.org/orm/downloads/;
2、连接数据库需要的jar文件,不同数据库需要下载不同的jar文件;
3、解压下载的hibernate,将hibernate-release-4.2.17.Final\lib\required中的jar文件导入项目中,如何创建java项目这里不再详细说明;
4、在项目根目录创建hibernate.cfg.xml文件,文件内容如下:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <!--连接数据库的驱动--> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!--连接数据库的用户名--> <property name="connection.username">zhou</property> <!--连接数据库的密码--> <property name="connection.password">123456</property> <!--连接数据库的url--> <proper