David David -4 years ago 138
Java Question

MySQL ConnectorJ with multiple SQL statements

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

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?

Answer Source

Perhaps allowMultiQueries?


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download