[CONJ-1102] BatchUpdateException.getUpdateCounts() returns SUCCESS_NO_INFO but expects EXECUTE_FAILED Created: 2023-08-22  Updated: 2023-12-01  Resolved: 2023-10-26

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: 3.2.0, 3.1.4
Fix Version/s: 3.3.0

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

MariaDB 10.11



 Description   

According to JDBC document:
_If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following:
A value of EXECUTE_FAILED – indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails_

In the test case below, MariaDB connector insert '2006-04-01', '2010-10-02', '2019-04-11' into table t1, however, e.getUpdateCounts() returns 1, 1, -2(SUCCESS_NO_INFO).
I think the expected returned results are 1, -3(EXECUTE_FAILED), 1, because the second batch insert failed and the third insert executed successfully and MySQL connector returns 1, -3, 1 as I expected.

@Test
public void test() throws SQLException {
    String url = "jdbc:mariadb://localhost:3366/test?user=user&password=password";
 
    Connection con = DriverManager.getConnection(url);
    Statement stmt = con.createStatement();
    stmt.execute("DROP TABLE IF EXISTS t1");
    stmt.execute("CREATE TABLE t1(c0 DATE UNIQUE PRIMARY KEY NOT NULL)");
    stmt.execute("INSERT INTO t1 VALUES ('2010-10-02')");
    stmt.close();
 
    try (Statement st = con.createStatement();){
        st.addBatch("INSERT INTO t1 VALUES ('2006-04-01')");
        st.addBatch("INSERT INTO t1 VALUES ('2006-04-01')");
        st.addBatch("INSERT INTO t1 VALUES ('2019-04-11')");
        st.executeBatch();
    } catch (BatchUpdateException e) {
        System.out.println("error: " + e);
        int[] res = e.getUpdateCounts();
        System.out.print("batch res: ");
        for (int r : res) {
            System.out.print(r + " ");
        }
        System.out.println();
    }
  
    con.close();
}


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