我正在尝试在启动期间创建示例表数据。我在BootStrap.groovy
文件中有以下代码。
但是Sql.newInstance
给出例外。
如何在启动期间运行mysqldump
脚本?
println "developmnet creating table"
String sqlString = servletContext.getResourceAsStream("/data/table_dump.sql").text
def db = [url:grailsApplication.config.dataSource.url, user:grailsApplication.config.dataSource.username, password:grailsApplication.config.dataSource.password, driver:grailsApplication.config.dataSource.driverClassName]
println "DataBase"+ db
def cls = Class.forName(db.driver).newInstance();
Sql sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
sql.execute(sqlString)