hibernate.cfg.xml
利用SQL数据库:
<?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 >
<!--数据库JDBC驱动类-->
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<!--数据库密码-->
<property name="hibernate.connection.password"></property>
<!--数据库的URL-->
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;databaseName=demo</property>
<!--数据库的用户名-->
<property name="hibernate.connection.username">sa</property>
<!--每个数据库都有其对应的Dialet以匹配其平台特性-->
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/mytest/entity/TestUser2.hbm.xml" />
</session-factory>
</hibernate-configuration>
利用Oracle9i数据库:
<session-factory>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:Oracle1
</property>
<property name="connection.username">hello</property>
<property name="connection.password">hello</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="show_sql">true</property>
<mapping resource="com/mytest/entity/TestUser2.hbm.xml" />
</session-factory>
利用:mySql数据库:
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/quickstart</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">pwd</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver(或org.gjt.mm.mysql.Driver)</property>
<property name="show_sql">true</property>
<mapping resource="com/bbs/hibernate/User.hbm.xml"></mapping>
</session-factory>
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/quickstart
hibernate.connection.username root
hibernate.connection.password
数据源的配置:
<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>