Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is correct way to close statement , connection , resultset...

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is correct way to close database objects ?
should we also close them again in catch(---) block ?
should we have a finally block and close them there ?


thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raminaa,
It is correct to close database resources in a finally block to guarantee they get closed. It is the same idea for statements, connections and resultsets.
As an example:


As you can see, this is on the verbose side. Most people write a utility method so they can just call: DatabaseUtils.close(rs)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic