Bug #77383 allowMultiQueries only works if first parameter in connection string
Submitted: 17 Jun 2015 9:09 Modified: 17 Jun 2015 10:08
Reporter: Chris Blackwell Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.35 OS:Any
Assigned to: CPU Architecture:Any

[17 Jun 2015 9:09] Chris Blackwell
Description:
With the connection string

jdbc:mysql://localhost:3306/test?allowMultiQueries=true&characterEncoding=UTF-8

you can execute sql with multiple statements, for example

select 1; select 2;

However if allowMultiQueries is not the first parameter, eg.

jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&allowMultiQueries=true

the same sql throws an exception. it makes no difference what parameter is placed before allowMultiQueries

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select 2' at line 2

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method):-2
 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62):62
 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45):45
 	at java.lang.reflect.Constructor.newInstance(Constructor.java:422):422
 	at com.mysql.jdbc.Util.handleNewInstance(Util.java:389):389
 	at com.mysql.jdbc.Util.getInstance(Util.java:372):372
 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980):980
 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835):3835
 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771):3771
 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435):2435
 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582):2582
 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531):2531
 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2489):2489
 	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:848):848
 	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742):742

How to repeat:
with

import java.sql.*; 

class MySQLMultiQueryTest { 

  public static void main (String[] args) { 
    try {
      Class.forName("com.mysql.jdbc.Driver"); 
      Connection conn = DriverManager.getConnection(args[0],args[1],args[2]);  
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT 1; SELECT 2;");      
      System.out.println("ok");  
    }
    catch (Exception e) {
      System.out.println("failed");        
      e.printStackTrace(System.out);
    } 
  } 
} 

execute

java -cp mysql-connector-java-5.1.35.jar:. MySQLMultiQueryTest "jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&allowMultiQueries=true" user password
[17 Jun 2015 9:47] MySQL Verification Team
Hello Chris Blackwell,

Thank you for the report and test case.

Thanks,
Umesh
[17 Jun 2015 9:56] MySQL Verification Team
May be issue with & instead of & in url?

[umshastr@hod03]/export/umesh/server/binaries/mysql-5.6.26: javac  MySQLMultiQueryTest.java
[umshastr@hod03]/export/umesh/server/binaries/mysql-5.6.26: java -classpath '.:/home/umshastr/bugs/mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar' MySQLMultiQueryTest
ok
[umshastr@hod03]/export/umesh/server/binaries/mysql-5.6.26: cat MySQLMultiQueryTest.java
import java.sql.*;

class MySQLMultiQueryTest {

  public static void main (String[] args) {
    try {
                        Class.forName("com.mysql.jdbc.Driver").newInstance();
                        String url = "jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&allowMultiQueries=true";
                        Connection conn = DriverManager.getConnection(url, "ushastry", "123");
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT 1; SELECT 2;");
      System.out.println("ok");
    }
    catch (Exception e) {
      System.out.println("failed");
      e.printStackTrace(System.out);
    }
  }
}
[17 Jun 2015 10:08] Chris Blackwell
Hi Umesh

Yes thats exactly the issue. The url was generated by another library with & in it, so i will file a bug with them to replace with &

Thanks
[17 Jun 2015 10:11] MySQL Verification Team
Thanks for confirming!

Regards,
Umesh