Hi, I have the following code:
Connection c = null;
try {
...
//get a connection from pool
...
c.setAutoCommit(false);
...
if(condition) {
return;
}
//do some update in the database
...
c.commit();
} catch(SQLException sqle) {
//rollback transaction
return;
} finally {
//close connection
}
If a specific condition happens during the transaction, then I just close the connection and return without commiting. In the docs it says closing a connection releases all database and jdbc resources, but when getting a connection from a pool, closing it may just return it to the pool. Also, the docs say that commit releases any database locks the connection held. If the connection was holding any database locks and I close without commiting, does it mean that the locks are still held by the connection now in the pool? Should I always commit a transaction before closing the connection?