如何模仿PreparedStatement来生成有效的SQL查询(Sql#withBatch)
这是我的代码:
// 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);
}
我目前正在寻找一种在 withBatch 中模拟 preparedstatement (funcThatMimicsPrepStat) 的方法,该方法仅适用于 Statement。任何建议都非常欢迎。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Groovy 1.8.0 尚不支持它,但看起来下一个小版本之一将支持它。 主干源代码 有几个非常有用的例子。下面是一个使用
PreparedStatement
的示例:我想您可以获取该代码片段或等待 Groovy 1.8.x 版本。
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.