1、在hibernate.properties中指定
/*显示实际操作数据库时的SQL */
hibernate.properties hibernate.show_sql = true
/* SQL方言,这边设定的是MySQL */
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
/*JDBC驱动程序 */
hibernate.connection.driver_class = com.mysql.jdbc.Driver
/* JDBC URL -->
hibernate.connection.url = jdbc:mysql://localhost/HibernateTest
/* 数据库使用者 */
hibernate.connection.username = caterpillar
/* 数据库密码 */
hibernate.connection.password = 123456
2、在hibernate.cfg.xml中指定
<hibernate-configuration>
<session-factory>
/* 显示实际操作数据库时的SQL*/
<property name="show_sql">true</property>
/*SQL方言,这边设定的是MySQL*/
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
/* JDBC驱动程序 */
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
/* JDBC URL*/
<property name="connection.url">jdbc:mysql://localhost/HibernateTest</property>
/* 数据库使用者*/
<property name="connection.username">caterpillar</property>
/* 数据库密码*/
<property name="connection.password">123456</property>
/*对象与数据库表格映像文件*/
<mapping resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
需要注意的是SQLServer2000与SQLServer2005的驱动程序及URL格式的不同
SQLServer2000:
driver:com.microsoft.jdbc.sqlserver.SQLServerDriver
url:jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Example
SQLServer2005
driver:com.microsoft.sqlserver.jdbc.SQLServerDriver
url:jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Example