This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes ResultSet doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSet doubt" Watch "ResultSet doubt" New topic

ResultSet doubt

Lalit mishra
Ranch Hand

Joined: Sep 01, 2005
Posts: 100
If we have a Resultset/Statement open and
if we doesnt closed the Resultset/Statement.
Rather we make ResultSet/Statement null.
will the ResultSet/Statement will be closed ?
Will there be any performance bottleneck on my Database
Lalit M.
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Lalit,

If you set them to null, they won't be closed.

About performance: a few years ago I worked on a project with a DB2 database, and after 250 unclosed Resultsets the webapplication just could not get anymore data from the database (the application seemed to "hang").

In short: close the connections, statements and resultsets.
(do it in a finally block, so they will always get closed, even when an exception occurs).

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

See the following thread:

Closing JDBC Resources

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I got tired of writing try-catch blocks around close calls and made this utility method:

It will close anything with a close() method. There is a closeable interface in the most recent JDKs so you could close some things without this reflection stuff. Note that null objects and objects that don't have close() methods all wind up in the catch.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: ResultSet doubt
It's not a secret anymore!