Hibernate 不同数据库的连接及SQL方言

配置Hibernate连接不同数据库
本文介绍了如何使用Hibernate框架配置连接多种数据库的方法,包括MySQL、SqlServer和Oracle等,并提供了具体的配置示例及可能遇到的方言设置错误。

<!--MySql 驱动程序 eg.mysql-connector-java-5.0.4-bin.jar-->
  <propertyname="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

  <!-- JDBC URL -->
  <propertyname="connection.url">jdbc:mysql://localhost/dbname?characterEncoding=gb2312</property>

  <!-- 数据库用户名-->
  <propertyname="connection.username">root</property>

  <!-- 数据库密码-->
  <propertyname="connection.password">root</property>
 
 
  <!--Sql Server 驱动程序 eg.jtds-1.2.jar-->
  <propertyname="dialect">org.hibernate.dialect.SQLServerDialect</property>
  <propertyname="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

  <!-- JDBC URL -->
  <propertyname="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbname</property>

  <!-- 数据库用户名-->
  <propertyname="connection.username">sa</property>

  <!-- 数据库密码-->
  <propertyname="connection.password"></property>

 
 
  <!--Oracle 驱动程序ojdbc14.jar-->
  <propertyname="dialect">org.hibernate.dialect.OracleDialect</property>
  <propertyname="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

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

  <!-- 数据库用户名-->
  <propertyname="connection.username">test</property>

  <!-- 数据库密码-->
  <propertyname="connection.password">test</property>



如果出现如下错误,则可能是HibernateSQL方言(hibernate.dialect)设置不正确。
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver forJDBC][SQLServer]'last_insert_id' 不是可以识别的 函数名。

RDBMS

方言

 

DB2

org.hibernate.dialect.DB2Dialect

DB2 AS/400

org.hibernate.dialect.DB2400Dialect

DB2 OS390

org.hibernate.dialect.DB2390Dialect

PostgreSQL

org.hibernate.dialect.PostgreSQLDialect

MySQL

org.hibernate.dialect.MySQLDialect

MySQL with InnoDB

org.hibernate.dialect.MySQLInnoDBDialect

MySQL with MyISAM

org.hibernate.dialect.MySQLMyISAMDialect

Oracle (any version)

org.hibernate.dialect.OracleDialect

Oracle 9i/10g

org.hibernate.dialect.Oracle9Dialect

Sybase

org.hibernate.dialect.SybaseDialect

Sybase Anywhere

org.hibernate.dialect.SybaseAnywhereDialect

Microsoft SQL Server

org.hibernate.dialect.SQLServerDialect

SAP DB

org.hibernate.dialect.SAPDBDialect

Informix

org.hibernate.dialect.InformixDialect

HypersonicSQL

org.hibernate.dialect.HSQLDialect

Ingres

org.hibernate.dialect.IngresDialect

Progress

org.hibernate.dialect.ProgressDialect

Mckoi SQL

org.hibernate.dialect.MckoiDialect

Interbase

org.hibernate.dialect.InterbaseDialect

Pointbase

org.hibernate.dialect.PointbaseDialect

FrontBase

org.hibernate.dialect.FrontbaseDialect

Firebird

org.hibernate.dialect.FirebirdDialect



 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值