This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to close the statement object in the method that returns a resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to close the statement object in the method that returns a resultset" Watch "How to close the statement object in the method that returns a resultset" New topic
Author

How to close the statement object in the method that returns a resultset

anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
hi,
i have a database class which does all my database operations. I am using connection pooling.
One of my function is executequery which takes in the SQL query as a parameter and retuns the Resultset.
Now the problem is that i am able to release the connection but i am not able to close the statment object. If I close the statement object my result set also goes. Is there any way to solve this, or my approach of returning the resultset is wrong ???
TIA
Anil
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Although this topic is different, I posted 2 different ways to handle your situation at http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=3&t=001893
The first is returning an array list instead of a resultset. The second is create the statement/resultset at the class level. You then pass the resultset from your method, use it, then when you are done with it, have a method in which you can close the resultset/statement. See the above link for more details.
Jamie
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
Thanks Jamie
But i am using the connection pooling and i am able to release the connection. But cant close the statement. if i close the statement, i am not bale to access the resultSet.
Here is how my code for the database class looks looks.

Is this a problem in design ???
this code works fine but as i am not closing the statement, will it have performance issues ???
TIA
Anil
Wagner Danda
Greenhorn

Joined: Jul 10, 2001
Posts: 26

BUT REMEMBER: it�s up to the client that gets the ResultSet to close it...
Wagner Danda
[ January 16, 2002: Message edited by: Wagner Danda ]
[ January 16, 2002: Message edited by: Wagner Danda ]

Wagner Danda<br />Sun Certified Programmer for Java 2 Platform
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
How did you solve the problem ???
then
is returning an array list instead of a resultset the only solution ???
TIA
Anil
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
how about using the rowset and closing the recordset in my database class
and returning the rowset ???
 
 
subject: How to close the statement object in the method that returns a resultset