I'm implementing doWork api in the method
Code:
public void execute(Connection connection) throws SQLException
I am doing my work and obtaining a ResultSet. Historically I would have a try/catch/finally section that I would use to close the ResultSet, but with this API the try/catch/finally encloses the inner class. How do I close the ResultSet if an exception it thrown? If I declare the ResultSet outside the inner class I need to make it final so it can be accessed inside the inner class, but in that case I can't assign it to the result of my query because it is final. If I declare the ResultSet inside the execute method and an exception is thrown I can't close the result set because the outer class knows nothing of the varibles declared in the inner class. I guess I could implement a try/catch/finally section inside the execute method and then re-throw the SQLException as I believe the finally clause will still be called and then the SQLException will bubble up. Is this how I should handle this issue? Is there a better way to handle the issue?