I have a brand new Grails 2.3.0 app, completely unconfigured—just out of the box settings after running grails create-app. I've found that groovy.sql.Sql code doesn't seem to work at all, and always triggers the following sql error:
java.sql.SQLException: No suitable driver found forjdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000
Here's an example of code that causes the No suitable driver found error, I've just thrown it in BootStrap.groovy. Again, this is the only piece of code added to a brand new app.
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 = {
}
}
I think I have tracked down the issue to the following default grails.project.fork settings. If I comment them out, everything works fine and the table is created successfully:
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]
]
Does the forked jvm block groovy sql class connectivity? I can't seem to figure out what's going on here.
groovy.sql.Sqlclass is used. I've edited the question with an example test that triggers the error. - dpcasady