1. 程式人生 > >Eclipse中hibernate連線mySQL資料庫練習

Eclipse中hibernate連線mySQL資料庫練習

下面開始搭建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"?> 
 <!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 方言 -->