Grails 项目配置数据连接的配置文件的编写 Grails连接Oracle grails连接Mysql 的配置文件

grails连接Oracle的配置如下:

  1. dataSource {
  2.   //  pooled = true
  3.   //  driverClassName = "org.h2.Driver"
  4.   //  username = "sa"
  5.   //  password = ""
  6. }
  7. hibernate {
  8.     cache.use_second_level_cache = true
  9.     cache.use_query_cache = false
  10.     cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
  11. }
  12. // environment specific settings
  13. environments {
  14.     development {
  15.         dataSource {
  16.             dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
  17.             driverClassName = "oracle.jdbc.driver.OracleDriver"  //首先需要导入Oracle的数据库及驱动包   我使用的是Ojdbc6.jar
  18.             url = "jdbc:oracle:thin:@localhost:1521:orcl"  //数据库的Url 地址, localhost:ip地址,1521 端口号,orcl数据库名,创建的数据存储空间
  19.             dialect = "org.hibernate.dialect.Oracle10gDialect"  //数据库方言
  20.             username = "zhiren"   //用户名
  21.             password = "zhiren"  //密码
  22.             logSql = true
  23.         }
  24.     }
  25.     test {
  26.         dataSource {
  27.             dbCreate = "update"
  28.             url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
  29.         }
  30.     }
  31.     production {
  32.         dataSource {
  33.             dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
  34.             driverClassName = "oracle.jdbc.driver.OracleDriver"
  35.             url = "jdbc:oracle:thin:@localhost:1521:orcl"
  36.             dialect = "org.hibernate.dialect.Oracle10gDialect"
  37.             username = "zhiren"
  38.             password = "zhiren"
  39.             logSql = true
  40.         }
  41.     }
  42. }

  grails  连接Mysql 数据库的配置文件

  1. dataSource {   //通用配置
  2.     pooled = true
  3.     driverClassName = 'com.mysql.jdbc.Driver' //连接Mysql的数据库驱动   我使用的是mysql-connector-java-5.1.5-bin.jar
  4.     dialect = org.hibernate.dialect.MySQL5InnoDBDialect  //数据库方言
  5. }
  6. hibernate {
  7.     cache.use_second_level_cache = true
  8.     cache.use_query_cache = true
  9.     show_sql = false
  10.     cache.provider_class = 'org.hibernate.cache.EhCacheProvider'
  11. }
  12. environments {
  13.     development {
  14.         dataSource {
  15.             dbCreate = "create-drop" 
  16.             url = 'jdbc:mysql://127.0.1.1/zhiren'   //连接数据库库的Url 地址,1127.0.1.1  数据库ip地址,zhiren ,数据库名字   我的没加端口号就可以连接的。正常的是需要加上 端口号:3306
  17.             username = 'root'  //用户名
  18.             password = 'root'  //密码
  19.         }
  20.     }
  21.     test {
  22.         dataSource {
  23.             url = 'jdbc:hsqldb:mem:testDb'
  24.         }
  25.     }
  26.     production {
  27.         dataSource {
  28.             dbCreate =  "create-drop"
  29.             url = 'jdbc:mysql://127.0.1.1/zhiren'
  30.             username = 'root'
  31.             password = 'root'
  32.         }
  33.     }
  34. }
原文地址:https://www.cnblogs.com/sm-myworks/p/3637857.html