I would like to execute some statements, and commit the entire batch at the end. I've tried the following approach:
connection.setAutoCommit(false); // Don't commit for each statement int returnCodes = pstmt.executeBatch(); // Execute all statements connection.setAutoCommit(true); // Back to normal state - future statements // will be committed instantly connection.commit(); // Commit our batch
Which fails miserably:
java.sql.SQLException: Can't call commit when autocommit=true --reference to the line with connection.commit()--
What's the right way to go? does
connection.setAutoCommit(true) commits all executed batch statements?