hibernate中连接SQLServer2008的配置文件hibernate.cfg.xml

来源:互联网 发布:大赢家缩水软件 编辑:程序博客网 时间:2024/05/18 01:41

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>

0 1
原创粉丝点击