从Groovy运行多个SQL语句 [英] Running multiple SQL statements from Groovy

查看:709
本文介绍了从Groovy运行多个SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  sql = Sql.newInstance(jdbc :mysql:// localhost /,usre,pass,com.mysql.jdbc.Driver)
sql.execute(USE foo;); //这个工程
sql.execute(USE foo; USE foo;); //这个失败很惨重

我得到的错误是你的SQL语法错误。

解决方案

您可以简单地将以下jdbc url参数添加到您的连接字符串中



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



从文档: p>


允许在一个语句
(true / false)中使用';'分隔
多个查询,默认为'false'


例如:

  Sql.newInstance(jdbc:mysql:// localhost?allowMultiQueries = true,usre,pass,com.mysql.jdbc.Driver)


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?

解决方案

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")

这篇关于从Groovy运行多个SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆