我有一个全新的 Grails 2.3.0 应用程序,完全未配置——运行grails create-app
. 我发现groovy.sql.Sql
代码似乎根本不起作用,并且总是触发以下sql错误:
java.sql.SQLException: No suitable driver found forjdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000
这是导致错误的代码示例No suitable driver found
,我刚刚将其放入BootStrap.groovy
. 同样,这是添加到全新应用程序中的唯一一段代码。
import groovy.sql.Sql
class BootStrap {
def grailsApplication
def init = { servletContext ->
try {
def sql = Sql.newInstance(grailsApplication.config.dataSource.url, grailsApplication.config.dataSource.username, grailsApplication.config.dataSource.password, grailsApplication.config.dataSource.driverClassName)
sql.execute("create table newtable")
}
catch(java.sql.SQLException ex) {
throw ex
}
}
def destroy = {
}
}
我想我已经将问题追溯到以下默认grails.project.fork
设置。如果我将它们注释掉,一切正常并且表创建成功:
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
分叉的 jvm 是否会阻止 groovy sql 类连接?我似乎无法弄清楚这里发生了什么。