Thursday, November 28, 2013

How to close resultset and statement in a finally when called in many functions?
































































































































Closing the statements should close any resultset associated with it though, so not all statements are closed perhaps. And if I look at your code, the closure of the statements is not inside a finally clause so there is no guarantee that they are closed if an exception happens.
































































































































You have a mountain of exception handling logic here, I would put some effort into reducing it to more expose hidden problems within it. For example, it pays to create utility safe close() methods like this:
































































































































































































Java Code:







































































































































public static void close(Statement stm){
if(stm != null){
try { stm.close(); } catch(Throwable t){}
}
}





































































































































This way you don't have to do annoying repeating null-checks and SHOULD the close() of one statement fail for some reason, you're not going to create the highly unwanted situation of an exception being thrown from a finally clause.






























































































































































































No comments:

Post a Comment