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

BatchUpdateException.getUpdateCounts() returns SUCCESS_NO_INFO but expects EXECUTE_FAILED

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.2.0, 3.1.4
    • 3.3.0
    • batch
    • None
    • 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();
      }
      

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            dwenking Wenqian Deng
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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