[CONJ-364] executeBatch won't return an array of update counter when allowMultiQueries=true. Created: 2016-10-10  Updated: 2019-08-30  Resolved: 2019-08-30

Status: Closed
Project: MariaDB Connector/J
Component/s: aurora
Affects Version/s: 1.5.2, 1.5.3
Fix Version/s: 2.0.0-RC, 1.6.0

Type: Bug Priority: Minor
Reporter: Seonmi Anderson Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

AWS RDS Aurora 5.6.10a
mariadb-java-client 1.5.3


Issue Links:
Problem/Incident
is caused by CONJ-386 Aurora isn't compatible with useBatch... Closed

 Description   

 
try {
             String connMasterStr = "jdbc:mariadb://my-database-instance-endpoint.rds.amazonaws.com:3306/lodgingHistory?allowMultiQueries=true";
             Connection connMaster = DriverManager.getConnection(connMasterStr, "myUsername", "myPassword");
 
             String sql = "insert ignore into foo3 (bar) values (?)";
             PreparedStatement pstmt = connMaster.prepareStatement(sql);
 
             int [] vals = new int[4];
             int start = 106;
             int dup = 2;
             for(int i=0;i<3;i++)
             {
                 vals[i]=start+i;
                 pstmt.setString(1, new Integer(start+i).toString());
                 pstmt.addBatch();
             }
             // add the dup
             pstmt.setString(1, new Integer(dup).toString());
             pstmt.addBatch();
 
             int[] updateCounts = pstmt.executeBatch();
             System.out.println("inserted " + updateCounts.toString());
 
         } catch (Exception ex) {
             System.out.println("Exception recived " + ex.getMessage());
         }

When the app is executed in main, it stuck and won't return updateCounts. However, eclipse debugger is used to debug the issue, it works and returns an array of update counts. The old version of mariadb connector 1.4.6 and 1.4.4 return update counts as expected.



 Comments   
Comment by Diego Dupin [ 2016-11-07 ]

hi,

I failed to reproduced your issue :
using your example :

    public void testt() throws Exception {
        try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testj?user=root&allowMultiQueries=true")) {
            try (Statement statement = connection.createStatement()) {
                statement.execute("DROP TABLE IF EXISTS foo3");
                statement.execute("CREATE TABLE foo3 (bar varchar(50))");
 
                String sql = "insert ignore into foo3 (bar) values (?)";
                try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
                    int[] vals = new int[4];
                    int start = 106;
                    int dup = 2;
                    for (int i = 0; i < 3; i++) {
                        vals[i] = start + i;
                        pstmt.setString(1, new Integer(start + i).toString());
                        pstmt.addBatch();
                    }
 
                    // add the dup
                    pstmt.setString(1, new Integer(dup).toString());
                    pstmt.addBatch();
                    int[] updateCounts = pstmt.executeBatch();
                    System.out.println("inserted " + updateCounts.length); //show inserted 4
                    
                    
                    //show :
                    //values :  0 = 1
                    //values :  1 = 1
                    //values :  2 = 1
                    //values :  3 = 1
                    for (int i = 0; i < updateCounts.length; i++) {
                        System.out.println("values :  " + i + " = " + updateCounts[i]);
                    }
                }
            }
        }
    }

return good results.
Have you any other indication ?

Comment by Diego Dupin [ 2016-11-07 ]

reproduced using aurora.

Comment by Seonmi Anderson [ 2016-11-07 ]

Thanks Diego looking at this!

I was able to retrieve good results when it connects local server 'jdbc:mariadb://localhost:3306/'. However, it won't return results and hangs when it tried to connect aurora instance endpoint or cluster endpoint.

Comment by Diego Dupin [ 2016-11-08 ]

As a workaround, you can add option useBatchMultiSend=false.

Comment by Diego Dupin [ 2019-08-30 ]

corrected with https://jira.mariadb.org/browse/CONJ-477 in 1.6.0 and 2.0.0

Generated at Thu Feb 08 03:15:07 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.