Hibernate加载其数据库配置

 Hibernate加载其配置文件hibernate.properties和hibernate.cfg.xml,常用xml文件比较直观,方便管理, Hibernate 是一个流行的开源对象关系映射工具,方便连接不同数据库,更换数据库,只要修改Hibernate配置文件,大度减少项目的维护。
     完整的配置如下:

<? 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.url" > jdbc:hsqldb:hsql://localhost /test</ property >
        
< property  name ="connection.username" > sa </ property >
        
< property  name ="connection.password" ></ 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 >

        
<!--  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" > create </ property >

        
< mapping  resource ="../*.hbm.xml" />

    
</ session-factory >

</ hibernate-configuration >
     常用数据库连接
     MySql 3/4/5:
   < property  name ="dialect" > org.hibernate.dialect.MySQLDialect </ property >
   

   <
property  name ="connection.driver_class" > com.mysql.jdbc.Driver </ property >
   
< property  name ="connection.url" > jdbc:mysql://localhost:3306/test </ property >     
   
< property  name ="connection.username" > root </ property >
   
< property  name ="connection.password" > </property>
    Microsoft SQLServer (via jTDS):
   < property  name ="dialect" > org.hibernate.dialect.SQLServerDialect </ property >
   

   <
property  name ="connection.driver_class" > net.sourceforge.jtds.jdbc.Driver </ property >
   
< property  name ="connection.url" > jdbc:jtds:sqlserver://localhost:1433/test;useCursors=true </ property >     
   
< property  name ="connection.username" > sa </ property >
   
< property  name ="connection.password" ></ property >   
    IBM DB2:
   < property  name ="dialect" > org.hibernate.dialect.DB2Dialect </ property >
   

   <
property  name ="connection.driver_class" > com.ibm.db2.jcc.DB2Driver </ property >
   
< property  name ="connection.url" > jdbc:db2://localhost:50000/test </ property >     
   
< property  name ="connection.username" > db2inst1 </ property >
   
< property  name ="connection.password" ></ property >  
    Oracle:
   < property  name ="dialect" > org.hibernate.dialect.OracleDialect </ property >
   

   <
property  name ="connection.driver_class" > oracle.jdbc.driver.OracleDriver </ property >
   
< property  name ="connection.url" > jdbc:oracle:thin:@localhost:1521:test </ property >     
   
< property  name ="connection.username" > ora </ property >
   
< property  name ="connection.password" ></ property >
    Informix:
   < property  name ="dialect" > org.hibernate.dialect.InformixDialect </ property >
   

   <
property  name ="connection.driver_class" > com.informix.jdbc.IfxDriver </ property >
   
< property  name ="connection.url" > jdbc:informix-sqli://localhost:1526/test:informixserver=server1 </ property >     
   
< property  name ="connection.username" > root </ property >
   
< property  name ="connection.password" ></ property >   
   
< property  name ="connection.encoding" > true </ property >
    Sybase (via jTDS):
   < property  name ="dialect" > org.hibernate.dialect.SybaseDialect </ property >
   
   < property  name ="connection.driver_class" > net.sourceforge.jtds.jdbc.Driver </ property >
   
< property  name ="connection.url" > jdbc:jtds:sybase://localhost:7100/test;useCursors=true </ property >     
   
< property  name ="connection.username" > root </ property >
   
< property  name ="connection.password" ></ property >
    PostgreSQL:
   < property  name ="dialect" > org.hibernate.dialect.PostgreSQLDialect </ property >
   
   < property  name ="connection.driver_class" > org.postgresql.Driver </ property >
   
< property  name ="connection.url" > jdbc:postgresql://localhost:5432/test </ property >     
   
< property  name ="connection.username" > root </ property >
   
< property  name ="connection.password" ></ property >
    MaxDB(SAPDB):
   < property  name ="dialect" > org.hibernate.dialect.SAPDBDialect </ property >
   
   < property  name ="connection.driver_class" > com.sap.dbtech.jdbc.DriverSapDB </ property >
   
< property  name ="connection.url" > jdbc:sapdb://localhost/test </ property >     
   
< property  name ="connection.username" > root </ property >
   
< property  name ="connection.password" ></ property >

你可能感兴趣的:(oracle,Hibernate,jdbc,配置管理,Sybase)