• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Closing ResultSet questions

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following 2 bits of code. Currently I close rs only in finally in addition to all ps and connection. Thank you for your time.

1/


2/

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my opinion

code 1: Yes you should close the result set before assigning a new ResultSet object to the rs variable.

code 2: Yep same as above. Except in the case I would close the statement also. But I would change it to make sure your prepared statement can be cached. see below.

Of course according to the specs if you close a statement its result set will also be closed so if you are closing your statement in finally this probably isn't much of a problem. But I feel its always best to call close() explicitly on all JDBC objects.

I'd rewrite case 2 to be more like

[ December 06, 2006: Message edited by: Tim LeMaster ]
reply
    Bookmark Topic Watch Topic
  • New Topic