Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple SQL statements from Groovy

Tags:

mysql

groovy

I'm having problems running multiple SQL statements in one activaction from Groovy.

sql = Sql.newInstance("jdbc:mysql://localhost/", "usre", "pass", "com.mysql.jdbc.Driver")
sql.execute("USE foo; "); // this works
sql.execute("USE foo; USE foo;"); // this fails miserably

The error I'm getting is "You have an error in your SQL syntax". What gives?

like image 220
ripper234 Avatar asked Nov 26 '10 15:11

ripper234


1 Answers

You can simply augment the following jdbc url parameter to your connection string

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html#allowMultiQueries

From the docs:

Allow the use of ';' to delimit multiple queries during one statement (true/false), defaults to 'false'

For example:

Sql.newInstance("jdbc:mysql://localhost?allowMultiQueries=true", "usre", "pass", "com.mysql.jdbc.Driver")
like image 90
btiernay Avatar answered Oct 28 '22 23:10

btiernay