[CONJ-1130] Inconsistent Behavior of executeBatch After SQL Failure Created: 2023-12-05  Updated: 2023-12-06  Resolved: 2023-12-05

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   

The bug involves a discrepancy in the behavior of the executeBatch method in JDBC applications using MariaDB and MySQL connectors. Specifically, when executeBatch encounters an error in executing its batch of SQL statements, the subsequent behavior of a repeated executeBatch call differs between MariaDB and MySQL. In MariaDB, the failed statements from the previous executeBatch call are re-executed, whereas in MySQL, they are not.

@Test
public void test() throws SQLException {
    Connection con;
    Statement stmt;
    ResultSet rs;
    con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test1481?user=user&password=password");
    stmt = con.createStatement();
    stmt.execute("CREATE TABLE table1481_0(id TINYINT PRIMARY KEY,value SMALLINT);");
    stmt.addBatch("INSERT INTO table1481_0 VALUES(1, 1)");
    stmt.addBatch("INSERT INTO table1481_0 VALUES(1, 1)");
    try {
        stmt.executeBatch();
    } catch (BatchUpdateException e) {
    }
    stmt.execute("TRUNCATE table1481_0;");
    try {
        stmt.executeBatch();
    } catch (Exception e) {
    }
    rs = stmt.executeQuery("SELECT * FROM table1481_0");
    while (rs.next()) {
        System.out.println(rs.getInt(1)); // mariadb : 1, mysql: empty
    }
}


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