必选项:
hibernate.connection.username:访问的数据库用户名
hibernate.connection.password:访问的数据库密码
hibernate.connection.url:连接数据库的url
hibernate.connection.driver_class:连接数据库使用的驱动程序
hibernate.dialect:连接数据库所使用的方言
可选项:
show_sql:显示执行的sql语句
常见数据库的驱动程序、url、方言
1.mysql
驱动程序为:"com.mysql.jdbc.Driver", url为:"jdbc:mysql://localhost:3306/[DBName]"。方言:org.hibernate.dialect.MySQLDialect
2.oracle
驱动程序为:"oracle.jdbc.driver.OracleDriver", url为:"jdbc:oracle:thin:@[ip]:1521:[DBName]“方言:org.hibernate.dialect.OracleDialect
3.sql server
驱动程序为:"com.microsoft.jdbc.sqlserver.SQLServerDriver", url为:"jdbc:microsoft:sqlserver://[IP]:1433;DatabaseName=[DBName],方言:org.hibernate.dialect.SQLServerDialect
mysql的一个配置样例
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!-- hibernate方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- hibernate连接的数据库url -->
<property name="connection.url">jdbc:mysql://localhost/test</property>
<!-- hibernate数据库JDBC驱动 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- hibernate连接的数据库用户名和密码 -->
<property name="connection.username">root</property>
<property name="connection.password">han</property>
<property name="hibernate.show_sql">true </property>
<mapping resource="test/book.hbm.xml"/>
</session-factory>
</hibernate-configuration>
oracle的一个配置样例
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!-- hibernate方言 -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- hibernate连接的数据库url -->
<property name="connection.url">jdbc:oracle:thin:@10.105.240.9:1521:ORCL</property>
<!-- hibernate数据库JDBC驱动 -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- hibernate连接的数据库用户名和密码 -->
<property name="connection.username">grp_9_7</property>
<property name="connection.password">grp97</property>
<property name="hibernate.show_sql">true </property>
<property name="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</property>
<mapping resource="DAO/Assistant.hbm.xml"/>
<mapping resource="DAO/Course.hbm.xml"/>
<mapping resource="DAO/Homework.hbm.xml"/>
<mapping resource="DAO/Student.hbm.xml"/>
<mapping resource="DAO/Submittedwork.hbm.xml"/>
<mapping resource="DAO/Teacher.hbm.xml"/>
<mapping resource="DAO/Group.hbm.xml"/>
</session-factory>
</hibernate-configuration>