You can do this at BootStrap.groovy. If you add dependency injection for a dataSourcebean, you can use it with the instance groovy.sql.Sqlto insert:
import groovy.sql.Sql
class BootStrap {
def dataSource
def init = { servletContext ->
def sql = new Sql(dataSource)
sql.executeUpdate(
'insert into some_table(foo, bar) values(?, ?)',
['x', 'y'])
}
}
You will probably be better off using GORM, assuming these are tables that are managed using domain classes. For instance. run something likenew Book(author: 'me', title: 'some title').save()
source
share