Bug #113336 Inconsistent getUpdateCount() Behavior with allowMultiQueries
Submitted: 5 Dec 2023 9:05 Modified: 14 Jan 21:01
Reporter: Wenqian Deng Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.1.0 OS:Any
Assigned to: CPU Architecture:Any

[5 Dec 2023 9:05] Wenqian Deng
Description:
When allowMultiQueries=true is set in the connection URL, the getUpdateCount() method returns -1 after executing a batch of update and delete statements. In contrast, when allowMultiQueries=false (or not set), getUpdateCount() returns 0 under the same conditions.
The expected behavior is that the return value of getUpdateCount() should be consistent regardless of the allowMultiQueries setting, especially when no rows are affected by the executed statements.

How to repeat:
@Test
public void test() throws SQLException {
    Connection con = null;
    Statement stmt = null;
    con = DriverManager.getConnection("jdbc:mysql://localhost:3366/test5?user=user&password=password&allowMultiQueries=true");
    stmt = con.createStatement();
    stmt.executeUpdate("CREATE TABLE table343_0(id INT PRIMARY KEY,value TEXT(5));", 2);

    stmt = con.createStatement();
    stmt.addBatch("UPDATE table343_0 SET value = 'U8cuL9jRqqj1#wT*Dw8o3JuYQL6%$I#lBB1r1V&3x' WHERE id >= 741449035");
    stmt.addBatch("DELETE FROM table343_0 WHERE id <= -1946432626");
    stmt.addBatch("DELETE FROM table343_0 WHERE id <= -1749798027");
    stmt.executeBatch();

    System.out.println(stmt.getUpdateCount()); // -1 if allowMultiQueries
}
[6 Dec 2023 7:22] MySQL Verification Team
Hello Wenqian Deng,

Thank you for the report and test case.
Verified as described.

regards,
Umesh
[14 Jan 21:01] Edward Gilmore
Posted by developer:
 
 Added the following note to the MySQL Connector/J 9.6.0 release notes:		
 
Statement.getUpdateCount()</literal> returned differing values depending on whether
rewriteBatchedStatements was enabled.