Grails多数据源

dataSource {
pooled = true
driverClassName = "oracle.jdbc.driver.OracleDriver"


dialect = org.hibernate.dialect.Oracle10gDialect


}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
url = "jdbc:oracle:thin:@192.168.1.219:1521:sue"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
username = ""******""
password = "******"
//            logSql = true
}
dataSource_lookup {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
username = ""******""
password = ""******""
//            logSql = true
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:@192.168.1.219:1521:sue"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
username = ""******""
password = ""******""


}
dataSource_lookup {
dbCreate = "update"
url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
username = ""******""
password = ""******""
}


}
production {
dataSource {
dbCreate = "update"
//            url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
url = "jdbc:oracle:thin:@localhost:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
pooled = true
//            username = "scott"
username = ""******""
password = ""******""
dialect = org.hibernate.dialect.Oracle10gDialect
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
//                validationQuery="SELECT 1"
validationQuery="select 1 from dual"
}
}
dataSource_lookup {
dbCreate = "update"
//            url = "jdbc:oracle:thin:@192.168.1.219:1521:rcjl"
//            url = "jdbc:oracle:thin:@"******":1521:rcjl"
url = "jdbc:oracle:thin:@localhost:1521:rcjl"
//            url = "jdbc:oracle:thin:@localhost:1521:rcjl"
pooled = true
//            username = "scott"
username = ""******""
password = ""******""
dialect = org.hibernate.dialect.Oracle10gDialect
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
//                validationQuery="SELECT 1"
validationQuery="select 1 from dual"
}
}
}
}


在按制器或服务中直接定义就可以用
import groovy.sql.Sql




class TestController {


def dataSource_lookup


def index() {}
def testname(){
      def sql=new Sql(dataSource_lookup)
def a=sql.rows("select * from T_BASE where sf_id='650203199109142128'")


}
}


在域类中
class ZipCode {
   String code


   static mapping = {
      datasource 'lookup'
   }
}
class ZipCode {
   String code


   static mapping = {
      datasources(['lookup', 'DEFAULT'])
   }
}
class ZipCode {
   String code


   static mapping = {
      datasource 'ALL'
   }
}
class ZipCode {
   String code


   static mapping = {
      datasources(['lookup', 'auditing'])
   }
}
def zipCode = ZipCode.auditing.get(42)

zipCode.auditing.save()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值