I'm trying to implement the change in database connection closing suggested in this question's answers. More than once, I've come across this block of code at the end of my try blocks:
try {
-Code-
} catch(DatabaseException de) {
if(conn != null)
try{
conn.rollback();
} catch(SQLException e) { }
throw de;
} catch(SQLException se) {
if(conn != null)
try {
conn.rollback();
} catch(SQLException e) { }
throw new DatabaseException("SQLException caught: "+se.getMessage());
} finally{
if(conn != null)
try{
conn.rollback();
conn.rollback();
conn.close();
} catch(SQLException e) { }
}
This absolutely baffles me - why would we need to rollback our connection twice before closing it in a Finally block, when we're already catching the rollback separately?
exception
. Thecatch
in thefinally
block is there to guarantee that the rollback occurs if it is needed. Kinda like mashing the mouse button harder to get a better result.finally
block. They seem like a cut-and-pase mistake to me...