Hibernate configuration to connect to the database can facilitate our operation of Pojo, saving a lot of time and code. The following is a description of the configuration required to connect different databases in Hibernate.cfg.xml.
Need a database driver package can click here to download: Database jar package: http://pan.baidu.com/s/1jGKEEY6 Password: okq0
1. Hibernate connection to MySQL database
1 <?XML version= ' 1.0 ' encoding= ' UTF-8 '?>2 <!DOCTYPE hibernate-configuration Public3 "-//hibernate/hibernate Configuration DTD 3.0//en"4 "Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">5 <!--Generated by MyEclipse Hibernate Tools. -6 <hibernate-configuration>7 <session-factory>8 <!--Configuring JDBC Connection Properties -9 < Propertyname= "Myeclipse.connection.profile">Ten Com.mysql.jdbc.Driver One </ Property> A < Propertyname= "Connection.url"> - jdbc:mysql://localhost:3306/basehibernate - </ Property> the < Propertyname= "Connection.username">Root</ Property> - < Propertyname= "Connection.password">Sa</ Property> - < Propertyname= "Connection.driver_class"> - Com.mysql.jdbc.Driver + </ Property> - < Propertyname= "dialect"> + Org.hibernate.dialect.MySQLDialect A </ Property> at - <!--Auto-Build table - - < Propertyname= "Hbm2ddl.auto">Update</ Property> - <!--automatic submission, no words may appear after Insert database no data - - < Propertyname= "Connection.autocommit">True</ Property> - in <!--Pojo class using hibernate annotation - - <Mappingclass= "Com.basehibernate.pojo.Department" /> to <Mappingclass= "Com.basehibernate.pojo.Employee" /> + </session-factory> - </hibernate-configuration>
2. Hibernate connect to Oracle Database
1 <?XML version= ' 1.0 ' encoding= ' UTF-8 '?>2 <!DOCTYPE hibernate-configuration Public3 "-//hibernate/hibernate Configuration DTD 3.0//en"4 "Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">5 <!--Generated by MyEclipse Hibernate Tools. -6 <hibernate-configuration>7 <session-factory>8 <!--Configuring JDBC Connection Properties -9 < Propertyname= "Connection.driver_class">Ten Oracle.jdbc.driver.OracleDriver One </ Property> A < Propertyname= "Connection.url"> - Jdbc:oracle:thin: @localhost: 1521:chanshuyi - </ Property> the < Propertyname= "Myeclipse.connection.profile">Oracle</ Property> - < Propertyname= "Connection.username">Csy</ Property> - < Propertyname= "Connection.password">Csy</ Property> - < Propertyname= "dialect">Org.hibernate.dialect.Oracle9Dialect</ Property> + - <!--Oracle-specific Commit changes - + < Propertyname= "Defaultautocommit">True</ Property> A <!--Auto-Build table - at < Propertyname= "Hbm2ddl.auto">Auto</ Property> - < Propertyname= "Show_sql">True</ Property> - <!--automatic submission, no words may appear after Insert database no data - - < Propertyname= "Connection.autocommit">True</ Property> - - <!--Pojo class using hibernate annotation - in <Mappingclass= "Com.xinpinv.pojo.Product" /> - <Mappingclass= "Com.xinpinv.pojo.BitInfo" /> to </session-factory> + </hibernate-configuration>
3. Hibernate Connect to Oracle Database
(MARK to write)