Hibernate连接三种数据库的配置文件hibernate.cfg.xml

       Hibernate连接数据库的配置文件为hibernate.cfg.xml,下面列出了连接三种数据库(SQL Server、Oracle、MySQL),hibernate.cfg.xml的必要配置。

连接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">

<hibernate-configuration>

    <session-factory>

        

        <property name="connection.driver_class">

            com.mysql.jdbc.Driver

        property>

        

        <property name="connection.url">

            jdbc:mysql://localhost:3306/mysqldb

        property>

        

        <property name="connection.username">rootproperty>

        

        <property name="connection.password">adminproperty>

        

        <property name="connection.pool_size">1property>

        

        <property name="dialect">

            org.hibernate.dialect.MySQLDialect

        property>

        

        <property name="show_sql">trueproperty>

        

        <property name="format_sql">trueproperty>

        

        <mapping resource="com/model/User.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">

 

<hibernate-configuration>

    <session-factory>

        

        <property name="connection.driver_class">

            oracle.jdbc.driver.OracleDriver

        property>

        

        <property name="connection.url">

            jdbc:oracle:thin:@127.0.0.1:1521:DBSQL

        property>

        

        <property name="connection.username">PERSONNEL_MANAGEproperty>

        

        <property name="connection.password">MWQproperty>

        

        <property name="dialect">

            org.hibernate.dialect.OracleDialect

        property>

        

        <property name="show_sql">trueproperty>

        

        <property name="format_sql">trueproperty>

        

        <property name="use_sql_comments">trueproperty>

        

        <mapping resource="com/chen/entity/users.hbm.xml" />

    session-factory>

hibernate-configuration>

连接SQL Server配置


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>

     

     <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=db_manpowerproperty>

      

     <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriverproperty>

      

     <property name="hibernate.connection.username">saproperty>

      

     <property name="hibernate.connection.password"/>

     

     <property name="show_sql">tureproperty>

      

     <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialectproperty>

      

     <property name="hibernate.jdbc.batch_size">16property>

      

     <mapping resource="com/chen/entity/Users.hbm.xml"/>

     session-factory>

 hibernate-configuration>

你可能感兴趣的:(Hibernate)