[CONJ-1138]  Inconsistency in Behavior of PreparedStatement After closeOnCompletion() Between MariaDB and MySQL Connectors Created: 2023-12-09  Updated: 2023-12-13  Resolved: 2023-12-13

Status: Closed
Project: MariaDB Connector/J
Component/s: MySQL compatibility
Affects Version/s: 3.3.1
Fix Version/s: 3.3.2

Type: Bug Priority: Major
Reporter: Wenqian Deng Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

In the test case, pstmt.closeOnCompletion() is called, which should set the PreparedStatement to close automatically when all its associated result sets are closed. The expectation, based on standard JDBC behavior, is that once the statement is closed (either explicitly or automatically), no further operations should be allowed on it.
However, the MariaDB Connector's behavior deviates from this expectation, as it allows a subsequent execute() call on the closed statement, whereas the MySQL Connector J throws a java.sql.SQLException stating "No operations allowed after statement closed."

@Test public void test() throws Exception {
    Connection con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test1551?user=user&password=password");
    PreparedStatement pstmt = con.prepareStatement("SELECT 1;");
    pstmt.execute();
    pstmt.closeOnCompletion();
    System.out.println(pstmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
    try {
        // mysql: java.sql.SQLException: No operations allowed after statement closed.
        // mariadb: true
        System.out.println(pstmt.execute());
    } catch (Exception e) {
        System.out.println(e);
    }
}


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