Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement and resultset closing

 
shashank beerla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this right way to do it ?

 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shashank beerla wrote:is this right way to do it ?

Do what?
 
shashank beerla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
closing the resultset and statement
 
shashank beerla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as you can see i am using single statement for multiple queries
 
Paul Clapham
Sheriff
Posts: 21136
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic