Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1230

If one batch fails all following batches fail incorrectly (Stored Procedures Only)

Details

    • Bug
    • Status: Open (View Workflow)
    • Blocker
    • Resolution: Unresolved
    • 3.5.1
    • None
    • None
    • None
    • Test container docker

    Description

      When using stored procedures, if one batch fails (e.g., due to a primary key or unique key violation), all subsequent batches in the same session also fail, even when there are no issues with the following batches.
      The stored procedure is essentially an Insert operation.

      Steps Taken:
      In the catch block, I ensure to:

      Call connection.rollback(); to roll back the current transaction.
      Call preparedStatement.clearBatch(); to clear any pending batches.
      These steps work as expected for regular CRUD operations but have no effect when the batch contains stored procedure calls.

      Attachments

        Activity

          diego dupin Diego Dupin added a comment -

          If i understand the issue well this sample must reproduce the issue :

          @Test
            public void failStoredProcedureTest2() throws Exception {
              Statement stmt = sharedConn.createStatement();
              stmt.execute("DROP PROCEDURE IF EXISTS workingStoreProcedure");
              stmt.execute("DROP TABLE IF EXISTS saveData");
              stmt.execute("CREATE TABLE saveData(i int PRIMARY KEY)");
              stmt.execute("CREATE PROCEDURE saveDataProc(val int) begin INSERT INTO saveData(i) VALUE (val); end");
           
              try (CallableStatement call1 = sharedConn.prepareCall("{call saveDataProc(?)}")) {
                call1.setInt(1, 1);
                call1.execute();
           
                call1.setInt(1, 1);
                assertThrows(SQLException.class, () -> call1.execute());
           
                call1.setInt(1, 2);
                call1.addBatch();
                call1.setInt(1, 3);
                call1.addBatch();
                call1.executeBatch();
           
                call1.setInt(1, 2);
                call1.addBatch();
                call1.setInt(1, 4);
                call1.addBatch();
                assertThrows(SQLException.class, () -> call1.executeBatch());
           
                call1.setInt(1, 5);
                call1.addBatch();
                call1.setInt(1, 6);
                call1.addBatch();
                call1.executeBatch();
              }
            }
          

          but didn't. Am i missing something ?

          diego dupin Diego Dupin added a comment - If i understand the issue well this sample must reproduce the issue : @Test public void failStoredProcedureTest2() throws Exception { Statement stmt = sharedConn.createStatement(); stmt.execute( "DROP PROCEDURE IF EXISTS workingStoreProcedure" ); stmt.execute( "DROP TABLE IF EXISTS saveData" ); stmt.execute( "CREATE TABLE saveData(i int PRIMARY KEY)" ); stmt.execute( "CREATE PROCEDURE saveDataProc(val int) begin INSERT INTO saveData(i) VALUE (val); end" );   try (CallableStatement call1 = sharedConn.prepareCall( "{call saveDataProc(?)}" )) { call1.setInt( 1 , 1 ); call1.execute();   call1.setInt( 1 , 1 ); assertThrows(SQLException. class , () -> call1.execute());   call1.setInt( 1 , 2 ); call1.addBatch(); call1.setInt( 1 , 3 ); call1.addBatch(); call1.executeBatch();   call1.setInt( 1 , 2 ); call1.addBatch(); call1.setInt( 1 , 4 ); call1.addBatch(); assertThrows(SQLException. class , () -> call1.executeBatch());   call1.setInt( 1 , 5 ); call1.addBatch(); call1.setInt( 1 , 6 ); call1.addBatch(); call1.executeBatch(); } } but didn't. Am i missing something ?

          People

            diego dupin Diego Dupin
            JakeR Jake Raeburn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.