Here is my code:
// my SQL query used with PreparedStatement before
def query = "INSERT INTO TAB_A (x,y) VALUES (?,?)
Sql myDb = Sql.newInstance(...)
myDb.withBatch(10000, {stmt ->
// I get parameters as an array
def params = getParams();
String rowQuery = funcThatMimicsPrepStat(query, params)
stmt.addBatch(rowQuery);
}
I currently looking for a way to miminc preparedstatement (funcThatMimicsPrepStat) inside withBatch, which works only with Statement. Any advice more than welcome.
Groovy 1.8.0 doesn’t support it yet but it looks like one of the next minor versions will support it. The trunk source code has a couple of examples that are really helpful. Here’s one example that uses a
PreparedStatement:I guess you could either snatch that piece of code or wait for a Groovy 1.8.x release.