What is considered best practices when cleaning up JDBC resources and why? I kept the example short, thus just the cleaning up of the ResultSet.
finally
{
I see no problem with your second (uncommon) version.
null, so an NPE will occur in rare cases. So I see no performance problem here.rs = nullThe only disadvantage - if we have more then one resource to close, then we'd have to add one try/catch for each resource, if we want to close as many resources as possible. Otherwise, we'd enter the catch clause with the first null and that could cause undiscored leaks.
So it would look like that:
finally {
try{rs.close(); }catch(Exception ignored){}
try{stmt.close();}catch(Exception ignored){}
try{conn.close();}catch(Exception ignored){}
}
... which is still readable and understandable. But, according to never change a common pattern - I'd stick to the old-fashioned way of testing null first and catching SQLException while closing.