日期:2014-05-16  浏览次数:20421 次

Grails配置外部数据库

在Grails项目中的conf文件夹下如图

image

打开DataSource文件作如下配置
这里链接的是mysql数据库
dataSource {
//连接池打开
??? pooled = true
//驱动名字
??? driverClassName = “com.mysql.jdbc.Driver”
//用户名
??? username = “root”
//密码
password = “root”
//数据库方言
??? dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
hibernate {
??? cache.use_second_level_cache = true
??? cache.use_query_cache = true
??? cache.provider_class = ‘net.sf.ehcache.hibernate.EhCacheProvider’
}
// 不同的模式
environments {
//开始模式
??? development {
??????? dataSource {
??????????? dbCreate = “update” // one of ‘create’, ‘create-drop’,'update’
??????????? url = “jdbc:mysql://localhost:3306/gralis?useUnicode=true&characterEncoding=UTF-8″
??????? }
??? }
//测试模式
??? test {
??????? dataSource {
???????????? dbCreate = “update” // one of ‘create’, ‘create-drop’,'update’
??????????? url = “jdbc:mysql://localhost:3306/gralis?useUnicode=true&characterEncoding=UTF-8″
??????? }
??? }
//发布模式
??? production {
??????? dataSource {
??????????? dbCreate = “update” // one of ‘create’, ‘create-drop’,'update’
??????????? url = “jdbc:mysql://localhost:3306/gralis?useUnicode=true&characterEncoding=UTF-8″
??????? }
??? }
}

同时在lib文件夹下添加mysql驱动包

?

?