hibernate.cfg.xml中的文件内容如下:
<?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">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<!-- <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
连接sqlserver2008的类库文件,务必写正确
<!-- <property name="connection.url">jdbc:hsqldb:hsql://localhost</property> -->
<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=hibernate</property>
连接sqlserver2008的路径文件:除数据库名之外,其他都一样(除非你改了数据库的端口号)
当时因为我把数据库名敲错了一个字母,几乎把一个项目中的所有配置文件全都检查一遍,汗..............
敲代码一定要仔细仔细再仔细
<property name="connection.username">sa</property>
<property name="connection.password">123456</property>
<!-- JDBC connection pool (use the built-in) -->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL dialect -->
<!-- <property name="dialect">org.hibernate.dialect.HSQLDialect</property> -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
查hibernate的API文档就可以
<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">update</property> -->
<!-- 去哪里找配置文件 -->
<!-- <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> -->
<mapping resource="com/bjsxt/hibernate/model/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>