Another way is to utilize the side effect of changing the auto-commit mode of the connection. If the setAutoCommit method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If setAutoCommit is called and the auto-commit mode is not changed, the call is a no-op. In this question, con.setAutoCommit(true) changes the auto-commit mode of the connection from false to true and therefore this call commits the changes.
So just to clarify, is setAutoCommit is called and only if it changes the commit mode does the transaction commit, correct?
So doing a con.setAutoCommit(false) at the beginning and again at the end of a block of code which has several db statmenet executeUpdate calls would mean that those statements did not get commited by that second autoCommit statement?
Might be obvious, but I just want to confirm... If you call setAutoCommit(false) and it changes the status from true to false - does it also commit all previous transactions (and autoCommit is disabled only going forward)?
Well, if the auto commit is being changed from true to false, there cannot be a preexiting previous transaction because every statement is executed and committed immediately when auto commit is true. So what do you think would be left to commit?