Eclipse中hibernate连接mySQL数据库练习
来源:互联网 发布:架子鼓谱软件 编辑:程序博客网 时间:2024/06/09 15:33
Eclipse中hibernate连接mySQL数据库练习
(采用的是hibernate中XML配置方式连接数据库,以后在更新其他方式的连接)
1.在eclipse中新建Java project项目,名称为:hibernateTest。右击项目名称,点击property,选择Java Build Path,加入需要导入的JAR包。
2.在src文件夹下,新建hibernate.cfg.xml配置文件,(连接数据库的参数信息)
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.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test
</property>
<!-- 数据库连接设置 -->
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<!-- show_sql 生成SQL语句输出到日志以供调式 -->
<property name="hibernate.show_sql">true</property>
<!-- SQL dialect 方言 -->
(采用的是hibernate中XML配置方式连接数据库,以后在更新其他方式的连接)
Hibernate就是Java后台数据库持久层的框架,也是目前企业用最多的数据库框架,主要是基于ORM -- object relationship Mapping,翻译成中文叫“对象关系映射”,也就是将SQL这种非面向对象语言转化成hibernation面向对象的写法,本文将通过在Eclipse下搭建HIbernate框架
我所使用的Hibernate版本是Hibernate3.3.2,Hibernate官网下载www.hibernate.org
下面开始搭建hibernate数据库:1.在eclipse中新建Java project项目,名称为:hibernateTest。右击项目名称,点击property,选择Java Build Path,加入需要导入的JAR包。
2.在src文件夹下,新建hibernate.cfg.xml配置文件,(连接数据库的参数信息)
hibernate.cfg.xml文件代码如下:
<?xml version="1.0" encoding="UTF-8"?>