具有多个SQL语句的MySQL ConnectorJ [英] MySQL ConnectorJ with multiple SQL statements

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

问题描述

另一个开发人员告诉我,有一个MySQL ConnectorJ选项可以打开/关闭.该开发人员说,将此jdbc选项设置为"on"后,可以运行以下形式的java jdbc查询:

Another developer tells me that there is a MySQL ConnectorJ option which can be turned on/off. This developer says that after turning this jdbc option to 'on', I can run a java jdbc query in the form:

Connection jdbc = session.connection();
PreparedStatement pstmt = jdbc.prepareStatement("Update myTable set myField = 1 where myId = 1; Update myTable set anotherField = 2 where myId = 2");
pstmt.execute();

运行该准备好的语句的想法是,它在一次执行中运行两个sql查询.我查看了 mysql文档,但是我找不到该选项.开发人员不会记住此设置的名称,但是可以确定它的存在.有谁知道哪个mysql选项控制此行为?

The idea behind running this prepared statement is that it runs two sql queries in a single execution. I've looked at the mysql documentation, but I haven't been able to find this option. The developer does not recall the name of this setting, but is certain that it exists. Does anyone know which mysql option controls this behavior?

推荐答案

也许allowMultiQueries?

Perhaps allowMultiQueries?

https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

允许使用';'在一条语句中分隔多个查询 (true/false),默认为'false',并且不影响addBatch() 和executeBatch()方法,它们依赖于 rewriteBatchStatements.

Allow the use of ';' to delimit multiple queries during one statement (true/false), defaults to 'false', and does not affect the addBatch() and executeBatch() methods, which instead rely on rewriteBatchStatements.

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

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