• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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
Sheriff
Posts: 37403
531
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
Boost this thread!