Java 7 Automatic Resource Management JDBC (try-with-resources statement)
try(Connection con = getConnection()) { try (PreparedStatement prep = con.prepareConnection(“Update …”)) { //prep.doSomething(); //… //etc con.commit(); } catch (SQLException e) { //any other actions necessary on failure con.rollback(); //consider a re-throw, throwing a wrapping exception, etc } } According to the oracle documentation, you can combine a try-with-resources block with a regular try block. IMO, … Read more