Spring连接MySQL、Oracle和SQL Server

蒋茂
2023-12-01


  1. applicationContext.xml的配置如下:
  2. <?xml version= "1.0" encoding= "UTF-8"?>
  3. <beans
  4. xmlns= "http://www.springframework.org/schema/beans"
  5. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
  7. <bean id= "dataSource" class= "org.apache.commons.dbcp.BasicDataSource">
  8. <!-- 连接MySQL-->
  9. <property name= "driverClassName" value= "com.mysql.jdbc.Driver"></property>
  10. <property name= "url" value= "jdbc:mysql://localhost:3306/mytest"></property>
  11. <property name= "username" value= "root"></property>
  12. <property name= "password" value= "root"></property>
  13. <!-- 连接Oracle
  14. <property name= "driverClassName" value= "oracle.jdbc.driver.OracleDriver"></property>
  15. <property name= "url" value= "jdbc:oracle:thin:@localhost:1521:orcl"></property>
  16. <property name= "username" value= "scott"></property>
  17. <property name= "password" value= "tiger"></property>
  18. -->
  19. <!-- 连接SQL Server
  20. <property name= "driverClassName" value= "com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
  21. <property name= "url" value= "jdbc:sqlserver://localhost:1433;databaseName=test"></property>
  22. <property name= "username" value= "sa"></property>
  23. <property name= "password" value= "yuji"></property>
  24. -->
  25. <property name= "maxActive" value= "100"></property>
  26. <property name= "maxIdle" value= "30"></property>
  27. <property name= "maxWait" value= "500"></property>
  28. <property name= "defaultAutoCommit" value= "true"></property>
  29. </bean>
  30. <bean id= "sessionFactory" class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  31. <property name= "dataSource" ref= "dataSource"></property>
  32. <property name= "hibernateProperties">
  33. <props>
  34. <!-- MySQL的方言-->
  35. <prop key= "hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  36. <!-- Oracle的方言
  37. <prop key= "hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
  38. -->
  39. <!-- SQL Server的方言
  40. <prop key= "hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
  41. -->
  42. <prop key= "hibernate.show_sql"> true</prop>
  43. </props>
  44. </property>
  45. <property name= "mappingResources">
  46. <list>
  47. <value>com/test/bean/User.hbm.xml</value>
  48. </list>
  49. </property>
  50. </bean>
  51. <bean id= "userDao" class= "com.test.dao.impl.UserDAOImpl" scope= "singleton">
  52. <property name= "sessionFactory">
  53. <ref bean= "sessionFactory"/>
  54. </property>
  55. </bean>
  56. <bean id= "userService" class= "com.test.service.impl.UserServiceImpl">
  57. <property name= "userDao" ref= "userDao"></property>
  58. </bean>
  59. <bean id= "saveUserAction" class= "com.test.action.user.SaveUserAction" scope= "prototype">
  60. <property name= "service" ref= "userService"></property>
  61. </bean>
  62. <bean id= "listUserAction" class= "com.test.action.user.ListUserAction" scope= "prototype">
  63. <property name= "service" ref= "userService"></property>
  64. </bean>
  65. <bean id= "removeUserAction" class= "com.test.action.user.RemoveUserAction" scope= "prototype">
  66. <property name= "service" ref= "userService"></property>
  67. </bean>
  68. </beans>
  1. Hibernate SQL方言 (hibernate.dialect)
  2. 数据库
  3. hibernate方言
  4. DB2 org.hibernate.dialect.DB2Dialect
  5. DB2 AS/ 400 org.hibernate.dialect.DB2400Dialect
  6. DB2 OS390 org.hibernate.dialect.DB2390Dialect
  7. PostgreSQL org.hibernate.dialect.PostgreSQLDialect
  8. MySQL org.hibernate.dialect.MySQLDialect
  9. MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
  10. MySQL with MyISAM org.hibernate.dialect. MySQLMyISAMDialect
  11. Oracle (any version) org.hibernate.dialect.OracleDialect
  12. Oracle 9i/10g org.hibernate.dialect.Oracle9Dialect
  13. Sybase org.hibernate.dialect.SybaseDialect
  14. Sybase Anywhere org.hibernate.dialect.SybaseAnywhereDialect
  15. Microsoft SQL Server org.hibernate.dialect.SQLServerDialect
  16. SAP DB org.hibernate.dialect.SAPDBDialect
  17. Informix org.hibernate.dialect.InformixDialect
  18. HypersonicSQL org.hibernate.dialect.HSQLDialect
  19. Ingres org.hibernate.dialect.IngresDialect
  20. Progress org.hibernate.dialect.ProgressDialect
  21. Mckoi SQL org.hibernate.dialect.MckoiDialect
  22. Interbase org.hibernate.dialect.InterbaseDialect
  23. Pointbase org.hibernate.dialect.PointbaseDialect
  24. FrontBase org.hibernate.dialect.FrontbaseDialect
  25. Firebird org.hibernate.dialect.FirebirdDialect

 类似资料: