Description:
This is a bug in QueryInfo.java in mysql-connector-j: executeQuery on a java.sql.Statement will fail with the below exception because the isResultSetProducingQuery check has a bug and returns false for “SELECT * FROM PrintOptions”
java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:81)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:55)
at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1238)
The bug is in QueryInfo:containsIntoClause which is just using com.mysql.cj.util.StringUtils.indexOfIgnoreCase to check for “INTO” in the select statement and returning true for any table name that has INTO as a substring.
containsIntoClause:892, QueryInfo (com.mysql.cj)
getQueryReturnType:855, QueryInfo (com.mysql.cj)
isResultSetProducingQuery:357, StatementImpl (com.mysql.cj.jdbc)
executeQuery:1237, StatementImpl (com.mysql.cj.jdbc)
How to repeat:
@Test
public void selectIntoBugTest() {
ResultSet rs = null;
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/unittest?user=unittest&password=PASSWORD");
Statement s = con.createStatement();
s.execute("DROP TABLE IF EXISTS PrintOptions");
s.execute("CREATE TABLE PrintOptions (id INT)");
rs = s.executeQuery("SELECT * FROM PrintOptions");
}catch(Exception x) {
x.printStackTrace(System.err);
}
assertNotNull(rs);
}
Suggested fix:
Change the indexOfIgnoreCase to use a regex that will include a check for white-space/bracket/@ (and possibly others) around the INTO
Description: This is a bug in QueryInfo.java in mysql-connector-j: executeQuery on a java.sql.Statement will fail with the below exception because the isResultSetProducingQuery check has a bug and returns false for “SELECT * FROM PrintOptions” java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:81) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:55) at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1238) The bug is in QueryInfo:containsIntoClause which is just using com.mysql.cj.util.StringUtils.indexOfIgnoreCase to check for “INTO” in the select statement and returning true for any table name that has INTO as a substring. containsIntoClause:892, QueryInfo (com.mysql.cj) getQueryReturnType:855, QueryInfo (com.mysql.cj) isResultSetProducingQuery:357, StatementImpl (com.mysql.cj.jdbc) executeQuery:1237, StatementImpl (com.mysql.cj.jdbc) How to repeat: @Test public void selectIntoBugTest() { ResultSet rs = null; try { Connection con = DriverManager.getConnection("jdbc:mysql://localhost/unittest?user=unittest&password=PASSWORD"); Statement s = con.createStatement(); s.execute("DROP TABLE IF EXISTS PrintOptions"); s.execute("CREATE TABLE PrintOptions (id INT)"); rs = s.executeQuery("SELECT * FROM PrintOptions"); }catch(Exception x) { x.printStackTrace(System.err); } assertNotNull(rs); } Suggested fix: Change the indexOfIgnoreCase to use a regex that will include a check for white-space/bracket/@ (and possibly others) around the INTO