my dog learned polymorphism*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "statement and resultset closing" Watch "statement and resultset closing" New topic

statement and resultset closing

shashank beerla

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

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11153

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

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

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

Joined: Oct 14, 2005
Posts: 18541

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.

subject: statement and resultset closing
Similar Threads
Null Pointer Exception
internal error: (No action instance for path /lookup could be created)
Singletons in servlets - threadsafe?
Cannot commit during managed transaction - Message-driven bean
Are there any problems using the same statement for multiple queries?