File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
anil bisht
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
anil bisht
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about using the rowset and closing the recordset in my database class
and returning the rowset ???
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic