I have a problem with try-with-resources and I am asking just to be sure. Can I use it, if I need to react on exception, and I still need the resource in catch block? Exampl
You can assign try block "con" reference to another method reference "connection".
java.sql.Connection connection = null;
try (java.sql.Connection con = createConnection())
{
connection = con;
con.setAutoCommit(false);
Statement stm = con.createStatement();
stm.execute(someQuery); // causes SQLException
}
catch(SQLException ex)
{
connection.rollback();
// do other stuff
}