[CONJ-1125] Inconsistency in Handling PreparedStatement.executeQuery() between MariaDB and MySQL Connectors Created: 2023-11-18  Updated: 2023-11-21

Status: Open
Project: MariaDB Connector/J
Component/s: MySQL compatibility
Affects Version/s: 3.3.0
Fix Version/s: 3.4

Type: Bug Priority: Major
Reporter: Wenqian Deng Assignee: Diego Dupin
Resolution: Unresolved Votes: 0
Labels: 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.



 Comments   
Comment by Diego Dupin [ 2023-11-21 ]

JDBC Specification clearly indicate that connector must throw exception, so yes, this has to be handled.
A new option 'strictMode' will be enable by default to ensure respecting spec, but that will permit having compatibility with actual behavior.

Generated at Thu Feb 08 03:20:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.