Hibernate 数据库连接配置与SQL方言大全

孔和风
2023-12-01
1. MySql连接配置

MySql数据库的hibernate连接设置,在hibernate.cfg.xml文件中

<hibernate-configuration>

<session-factory>

<property name="show_sql">true</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<property name="jdbc.fetch_size">50</property>

<property name="jdbc.batch_size">30</property>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

     <property name="connection.url">jdbc:mysql://localhost/dbname?

characterEncoding=gb2312</property>

<property name="connection.username">root</property>

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

<mapping resource="com/amigo/pojo/User.hbm.xml"/>

<mapping resource="com/amigo/pojo/Org.hbm.xml"/>

</session-factory>

</hibernate-configuration>

 

 mysql-connector-java-5.0.4-bin.jar

2. Sql Server连接配置

Sql Server数据库的hibernate在配置文件中配置。

连接部分

<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

<property

name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbname</property>

<property name="connection.username">sa</property>

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


jtds-1.2.jar

3. Oracle连接配置

Oracler数据库的hibernate在配置文件中配置。

连接部分

<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

<property name="connection.url">jdbc:oracle:thin:@localhost:1521:dbname</property>

<property name="connection.username">test</property>

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


 ojdbc14.jar

4. DB2连接配置

DB2数据库的hibernate在配置文件中配置。

<property name="connection.driver_class"> com.ibm.db2.jdbc.app.DB2Driver</property>

<property

name="connection.url"> jdbc:db2://localhost:5000/sample </property>  //sample为数据库名

<property name="connection.username">admin</property>

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


 db2jcc.jar


5.sybase连接配置

<property name="connection.driver_class">com.sybase.jdbc.SybDrive</property>

<property

name="connection.url"> jdbc:sybase:Tds:localhost:5007/myDB</property> ;//myDB为数据库名

<property name="connection.username">userid</property>

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


jconn3.jar

6. informix连接配置

<property name="connection.driver_class">com.informix.jdbc.IfxDrive</property>

<property

name="connection.url">jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver </property> ;

<property name="connection.username">testuser</property>

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

ifxjdbc.jar


7.PostgreSQL连接配置

<property name="connection.driver_class">org.postgresql.Driver</property>

<property

name="connection.url">jdbc:postgresql://localhost/myDB</property>;//myDB为数据库名

<property name="connection.username">myuser</property>

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

postgresql-8.1-405.jdbc3

 

 


8.access连接配置

<property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>

<property

name="connection.url">jdbc:odbc:Driver={MicroSoft..Access..Driver(*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb")</property> ;

<property name="connection.username">myuser</property>

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

access数据库的驱动为:sun.jdbc.odbc.JdbcOdbcDriver或者是com.hxtt.sql.access.AccessDriver

jar包:Access_JDBC30.jar


Hibernate SQL方言 (hibernate.dialect) 大全:

    

RDBMS方言
DB2org.hibernate.dialect.DB2Dialect
DB2 AS/400org.hibernate.dialect.DB2400Dialect
DB2 OS390org.hibernate.dialect.DB2390Dialect
PostgreSQLorg.hibernate.dialect.PostgreSQLDialect
MySQLorg.hibernate.dialect.MySQLDialect
MySQL with InnoDBorg.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAMorg.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)org.hibernate.dialect.OracleDialect
Oracle 9i/10gorg.hibernate.dialect.Oracle9Dialect
Sybaseorg.hibernate.dialect.SybaseDialect
Sybase Anywhereorg.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Serverorg.hibernate.dialect.SQLServerDialect
SAP DBorg.hibernate.dialect.SAPDBDialect
Informixorg.hibernate.dialect.InformixDialect
HypersonicSQLorg.hibernate.dialect.HSQLDialect
Ingresorg.hibernate.dialect.IngresDialect
Progressorg.hibernate.dialect.ProgressDialect
Mckoi SQLorg.hibernate.dialect.MckoiDialect
Interbaseorg.hibernate.dialect.InterbaseDialect
Pointbaseorg.hibernate.dialect.PointbaseDialect
FrontBaseorg.hibernate.dialect.FrontbaseDialect
Firebirdorg.hibernate.dialect.FirebirdDialect

 类似资料: