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

Inconsistent Behavior of executeBatch After SQL Failure

    XMLWordPrintable

Details

    Description

      The bug involves a discrepancy in the behavior of the executeBatch method in JDBC applications using MariaDB and MySQL connectors. Specifically, when executeBatch encounters an error in executing its batch of SQL statements, the subsequent behavior of a repeated executeBatch call differs between MariaDB and MySQL. In MariaDB, the failed statements from the previous executeBatch call are re-executed, whereas in MySQL, they are not.

      @Test
      public void test() throws SQLException {
          Connection con;
          Statement stmt;
          ResultSet rs;
          con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test1481?user=user&password=password");
          stmt = con.createStatement();
          stmt.execute("CREATE TABLE table1481_0(id TINYINT PRIMARY KEY,value SMALLINT);");
          stmt.addBatch("INSERT INTO table1481_0 VALUES(1, 1)");
          stmt.addBatch("INSERT INTO table1481_0 VALUES(1, 1)");
          try {
              stmt.executeBatch();
          } catch (BatchUpdateException e) {
          }
          stmt.execute("TRUNCATE table1481_0;");
          try {
              stmt.executeBatch();
          } catch (Exception e) {
          }
          rs = stmt.executeQuery("SELECT * FROM table1481_0");
          while (rs.next()) {
              System.out.println(rs.getInt(1)); // mariadb : 1, mysql: empty
          }
      }
      

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            dwenking Wenqian Deng
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.