Lets say I have code that roughly resembles something like this: (Using oracle 10G jdbc). Will the transaction be committed in this specific scenario?
public void someMethod(){
try {
OracleConnection connection = getConnectionFromPool();
connection.setAutoCommit(false);
// Do some transaction here - complete transaction, no errors occurred
...
//Throw my own exception here
throw new Exception("Custom Exception");
} catch (Exception e}
{
...
}
finally {
connection.setAutoCommit(true);
}
}
According to the JavaDocs , it should commit:
NOTE: If this 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.
BUT : if you rely on this, it means you rely on the driver to comply with this requirement - which is something I wouldn't do (I would never rely on something happing implicitely)
If you want to make sure your transaction is committed, call commit()
.
No. Either remove connection.setAutoCommit(false);
or
finally {
connection.commit();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.