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

开发 后端
本文讲述Hibernate不同数据库的连接及SQL方言。Hibernate不同数据库的连接可能会出现错误,有一种情况是由于Hibernate SQL方言设置不正确而导致的。

以下代码展示Hibernate不同数据库的连接。

  1. < !--MySql 驱动程序 eg. mysql-connector-java-5.0.4-bin.jar--> 
  2.    < property name="dialect">org.hibernate.dialect.MySQLDialect< /property> 
  3.    < property name="connection.driver_class">com.mysql.jdbc.Driver< /property> 
  4.  
  5.    < !-- JDBC URL --> 
  6.    < property name="connection.url">jdbc:mysql://localhost/dbname?characterEncoding=gb2312< /property> 
  7.  
  8.    < !-- 数据库用户名--> 
  9.    < property name="connection.username">root< /property> 
  10.  
  11.    < !-- 数据库密码--> 
  12.    < property name="connection.password">root< /property> 
  13.     
  14.     
  15.    < !--Sql Server 驱动程序 eg. jtds-1.2.jar--> 
  16.    < property name="dialect">org.hibernate.dialect.SQLServerDialect< /property> 
  17.    < property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver< /property> 
  18.  
  19.    < !-- JDBC URL --> 
  20.    < property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbname< /property> 
  21.  
  22.    < !-- 数据库用户名--> 
  23.    < property name="connection.username">sa< /property> 
  24.  
  25.    < !-- 数据库密码--> 
  26.    < property name="connection.password">< /property> 
  27.  
  28.  
  29.     
  30.    < !--Oracle 驱动程序 ojdbc14.jar--> 
  31.    < property name="dialect">org.hibernate.dialect.OracleDialect< /property> 
  32.    < property name="connection.driver_class">oracle.jdbc.driver.OracleDriver< /property> 
  33.  
  34.    < !-- JDBC URL --> 
  35.    < property name="connection.url">jdbc:oracle:thin:@localhost:1521:dbname< /property> 
  36.  
  37.    < !-- 数据库用户名--> 
  38.    < property name="connection.username">test< /property> 
  39.  
  40.    < !-- 数据库密码--> 
  41.    < property name="connection.password">test< /property> 

如果出现如下错误,则可能是Hibernate SQL方言 (hibernate.dialect)设置不正确。

Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][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

【编辑推荐】

  1. 强人Hibernate文档笔记(上)
  2. 强人Hibernate文档笔记(中)
  3. 强人Hibernate文档笔记(下)
  4. hibernate 数据库连接池
  5. hibernate 重复导入问题处理
责任编辑:book05 来源: 百度博客
相关推荐

2009-06-24 07:58:52

Hibernate多数

2009-09-25 13:18:15

Hibernate数据

2010-10-26 15:54:02

连接oracle数据库

2009-06-24 07:53:47

Hibernate数据

2009-06-24 07:59:49

Hibernate方言

2010-09-01 16:55:55

SQL删除连接

2009-06-16 11:11:25

JBoss目录数据库连接

2011-08-03 14:02:02

数据库连接ACCESS

2010-06-30 16:48:19

SQL Server数

2011-08-04 15:55:25

SQL Server数

2011-06-21 15:31:04

Qt 数据库 SQL

2010-04-08 18:54:32

Oracle数据库

2009-11-30 17:54:56

PHP连接Sql数据库

2009-04-30 09:28:05

SynonymOpenquerySQL Server

2009-06-24 07:57:17

HibernateAccess方言

2015-10-30 14:00:33

adosybaseodbc

2009-07-07 17:42:28

2011-08-09 09:31:39

SQL Server数connectionS

2010-09-13 15:55:17

SQL Server数

2010-08-24 09:29:37

内连接全连接
点赞
收藏

51CTO技术栈公众号