MySQL ConnectorJ with multiple SQL statements

不羁的心 提交于 2020-01-04 14:19:04

问题


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();

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?


回答1:


Perhaps allowMultiQueries?

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

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.



来源:https://stackoverflow.com/questions/9219552/mysql-connectorj-with-multiple-sql-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!