[CONJ-1104] PreparedStatement.executeBatch returns unexpected values Created: 2023-08-29  Updated: 2023-09-01  Resolved: 2023-09-01

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: 3.1.4
Fix Version/s: N/A

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


 Description   

See this test case:

@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 t0");
    stmt.execute("CREATE TABLE t0(c0 REAL SIGNED  PRIMARY KEY NOT NULL) engine=InnoDB");
    stmt.close();
    PreparedStatement pstmt = con.prepareStatement("INSERT INTO t0 VALUES(?)");
    for (int i = 0; i < 2; i++) {
        pstmt.setDouble(1, i);
        pstmt.addBatch();
    }
    int[] res = pstmt.executeBatch();
    for (int t : res) {
        System.out.println(t);
    }
}

I expect pstmt.executeBatch() returns 1, 1. However, Mariadb Connector J returns -2, -2.



 Comments   
Comment by Diego Dupin [ 2023-08-31 ]

That's because mariadb has a special BULK command that permits fast batching, but returning Statement.SUCCESS_NO_INFO ( =-2)
Could you give a try to newly released 3.2.0 : This has been rewamp in 3.2.0, BULK insert will returned expected value (and DELETE / UPDATE wont use BULK by default). This permit application that use optimistic locking to work as expected.

Comment by Wenqian Deng [ 2023-09-01 ]

Thanks for this quick response. Updating to 3.2.0 works.

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