Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchUpdateException.getUpdateCounts returns unexpected value -1 #450

Closed
dwenking opened this issue Aug 29, 2023 · 6 comments
Closed

BatchUpdateException.getUpdateCounts returns unexpected value -1 #450

dwenking opened this issue Aug 29, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@dwenking
Copy link

Describe the bug

According to JDBC doc:

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following:
1.A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
2.A value of SUCCESS_NO_INFO -- indicates that the command was processed successfully but that the number of rows affected is unknown
If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. 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:
3.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

The array returned by BatchUpdateException.getUpdateCounts should be A number greater than or equal to zero/SUCCESS_NO_INFO(-2)/EXECUTE_FAILED(-3). However in my test case, I got a -1, which is confusing.

Expected Behavior

The result does not include -1.

Current Behavior

When I printed the results of BatchUpdateException.getUpdateCounts, I got -1, -3.

Reproduction Steps

@Test
public void test() throws SQLException {
    String url = "jdbc:mysql:aws://localhost:3380/test?user=user&password=password&allowMultiQueries=true";
    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.execute("INSERT INTO t0 VALUES (1670697762)");

    Statement bstmt = con.createStatement();
    bstmt.addBatch("INSERT INTO t0 VALUES (1670697762)");
    bstmt.addBatch("INSERT INTO t0 VALUES (697762)");
    try {
        bstmt.executeBatch();
    } catch (BatchUpdateException e) {
        int[] res = e.getUpdateCounts();
        for (int r : res) {
            System.out.println(r);
        }
    }
}

Possible Solution

No response

Additional Information/Context

No response

The AWS JDBC Driver for MySQL version used

1.1.9

JDK version used

19

Operating System and version

MacOS

@dwenking dwenking added the bug Something isn't working label Aug 29, 2023
@crystall-bitquill
Copy link
Collaborator

Hi @dwenking,

Thanks for reaching out and raising this issue.

We'll take a look at this and keep you updated as we investigate.

Thank you for your patience!

@crystall-bitquill
Copy link
Collaborator

Hi @dwenking,

We've recently merged in a fix. Could you kindly check out our snapshot build and let us know if the issue persists?

Thank you!

@dwenking
Copy link
Author

Hi, I checked your snapshot and the latest 1.1.9 snapshot seems updated on July 26. I didn't find the new snapshot with the fix.

@crystall-bitquill
Copy link
Collaborator

Hi @dwenking, the snapshot build versions are incremented based on the current version, so the latest snapshot build is version 1.1.10.

@dwenking
Copy link
Author

Thanks for your kind reply. I checked 1.1.10 and the result no longer returns -1.

@crystall-bitquill
Copy link
Collaborator

Thanks for checking out the snapshot build! If the problem has been resolved, we'll be closing this issue now. If you have other questions or concerns, please feel free to reopen this issue or to create a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants