Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
3.3.0
-
None
Description
Using the MariaDB JDBC connector, the executeQuery() method on a PreparedStatement object does not throw an exception when used for an insert SQL statement.
However, when the same operation is performed using the MySQL JDBC connector, it throws a java.sql.SQLException stating that Statement.executeQuery() cannot issue statements that do not produce result sets.
The different behavior in handling PreparedStatement.executeQuery() will cause potential compatibility issues. For example:
@Test
|
public void test() throws SQLException { |
Connection con;
|
Statement stmt;
|
ResultSet rs;
|
con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test42?user=user&password=password"); |
stmt = con.createStatement(1004, 1008, 2); |
stmt.execute("CREATE TABLE table42_0(id INT PRIMARY KEY,value VARCHAR(100));"); |
stmt.close();
|
PreparedStatement pstmt = con.prepareStatement("INSERT INTO table42_0 VALUES(?, ?);"); |
pstmt.setObject(1, "1868598290"); |
pstmt.setObject(2, "'F^uNhSH.Cd;pH22.(xcX$Lr'"); |
pstmt.addBatch();
|
try { |
pstmt.executeQuery(); // Mysql connector throw java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets. |
} catch (Exception e) { |
}
|
rs = con.createStatement().executeQuery("SELECT * FROM table42_0;"); |
while (rs.next()) { |
System.out.println(rs.getObject(1) + " " + rs.getObject(2)); |
}
|
con.close();
|
}
|
In the test case, MariaDB connector inserts successfully while MySQL connector does not. Therefore, the results of select query after pstmt.executeQuery() are affected.