aspose file tools*
The moose likes Performance and the fly likes statement and resultset closing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "statement and resultset closing" Watch "statement and resultset closing" New topic
Author

statement and resultset closing

shashank beerla
Greenhorn

Joined: Jun 07, 2013
Posts: 26
is this right way to do it ?

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11229
    
  16

shashank beerla wrote:is this right way to do it ?

Do what?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
shashank beerla
Greenhorn

Joined: Jun 07, 2013
Posts: 26
closing the resultset and statement
shashank beerla
Greenhorn

Joined: Jun 07, 2013
Posts: 26
as you can see i am using single statement for multiple queries
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That's a pretty good attempt. The only problem is, the close() method can also throw an SQLException. At least it's declared that way. And yes, you're catching that exception. However if that exception were actually thrown, let's say at line 54 for example, then the PoolManager.returnConnection line would not be executed. So you aren't dealing with it adequately, if you want to be 100% bullet-proof. Even if line 54 threw an exception, you would want to carry on with the rest of the code in the finally-block.

And by the way setting a method's local variable to null is usually pointless, and when you do it immediately before leaving the method, it's always pointless.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: statement and resultset closing