-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: doWork api and SQLException
PostPosted: Wed Mar 14, 2012 6:24 pm 
Newbie

Joined: Wed Mar 14, 2012 5:37 pm
Posts: 2
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.