標籤:XML 表示 clip 控制台 批量 dial 儲存 name 位置
資料庫連接參數配置:
<?xml version=‘1.0‘ encoding=‘UTF-8‘?><!--表明解析本XML檔案的DTD文檔位置,DTD是Document Type Definition 的縮寫,即文件類型的定義,XML解析器使用DTD文檔來檢查XML檔案的合法性。hibernate.sourceforge.net/hibernate-configuration-3.0dtd可以在Hibernate3.1.3軟體包中的src\org\hibernate目錄中找到此檔案--> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!--聲明Hibernate設定檔的開始--> <hibernate-configuration> <!--表明以下的配置是針對session-factory配置的,SessionFactory是Hibernate中的一個類,這個類主要負責儲存HIbernate的配置資訊,以及對Session的操作--> <session-factory> <!--設定資料庫的驅動程式,Hibernate在串連資料庫時,需要用到資料庫的驅動程式--> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property> <!--設定資料庫的串連url:jdbc:mysql://localhost/hibernate,其中localhost表示mysql伺服器名稱,此處為本機,test是資料庫名--> <property name="hibernate.connection.url">jdbc:mysql://localhost/test </property> <!--串連資料庫是使用者名稱--> <property name="hibernate.connection.username">root </property> <!--串連資料庫是密碼--> <property name="hibernate.connection.password">admin </property> <!--資料庫連接池的大小--> <property name="hibernate.connection.pool.size">20 </property> <!--是否在後台顯示Hibernate用到的SQL語句,開發時設定為true,便於差錯,程式運行時可以在Eclipse的控制台顯示Hibernate的執行Sql語句。項目部署後可以設定為false,提高運行效率--> <property name="hibernate.show_sql">true </property> <!--jdbc.fetch_size是指Hibernate每次從資料庫中取出並放到JDBC的Statement中的記錄條數。Fetch Size設的越大,讀資料庫的次數越少,速度越快,Fetch Size越小,讀資料庫的次數越多,速度越慢--> <property name="jdbc.fetch_size">50 </property> <!--jdbc.batch_size是指Hibernate批量插入,刪除和更新時每次操作的記錄數。Batch Size越大,大量操作的向資料庫發送Sql的次數越少,速度就越快,同樣耗用記憶體就越大--> <property name="jdbc.batch_size">23 </property> <!--jdbc.use_scrollable_resultset是否允許Hibernate用JDBC的可滾動的結果集。對分頁的結果集。對分頁時的設定非常有協助--> <property name="jdbc.use_scrollable_resultset">false </property> <!--connection.useUnicode串連資料庫時是否使用Unicode編碼--> <property name="Connection.useUnicode">true </property> <!--connection.characterEncoding串連資料庫時資料的傳輸字元集編碼方式--> <property name="connection.characterEncoding">UTF-8</property> <!--hibernate.dialect 只是Hibernate使用的資料庫方言,就是要用Hibernate串連那種類型的資料庫伺服器。--> <!--指定對應檔為“com.teacher.bean.Users”--> <mapping class="com.teacher.bean.Users" /> </session-factory></hibernate-configuration>
本文出自:藝意
Hibernate架構 主設定檔(Hibernate.cfg.xml)待完善