File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes ResultSet is closed?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSet is closed??" Watch "ResultSet is closed??" New topic

ResultSet is closed??

sumana ar

Joined: Aug 06, 2003
Posts: 28
I'm trying to make an advanced search page in JSP where the user can search based on certain criteria...and I want the user to be able to leave some of the criteria blank
so i've done some thing like this,
String query = "Select * from <table_name> where";
if (value in param is not null) then
appended the condition to the query
finally, after appending the query would look something like this..
query = "SELECT * FROM emp WHERE (emp_id = 13 OR emp_id <> 55) AND (emp_name like 'SMIT%') ORDER BY emp_name, emp_no"
now i'm sending the whole query to a bean which return back the result set.
when i write ResultSet rs = beanid.exec(query);
i'm getting an error that the Result Set is exec is the method which returns the resultset
what could be the problem..some one plz help me solve the problem..
Gayathri Prasad
Ranch Hand

Joined: Jun 25, 2003
Posts: 116
Hi Sumana,
This might be of some help
Prasanna Kumar R.V
sumana ar

Joined: Aug 06, 2003
Posts: 28
hi gayatri..
this is what sandeep has said...
"You would need to use a different Statement object, if you want to do it in this way.
Statement stmt1 = myConn.createStatement();
query = "update TransactEJBTable set comments = '" + request.getParameter(strIndex) + "' where ResId = '" + ResId + "' and RevId = '" + RevId + "'";
that is what i'm doing...i've written the whole query in a seperate string and sending that string to the java bean method as a parameter..but the problem is not solved...can u plz look into this...i'm stuck here and not able to proceed further...
swathi java

Joined: Sep 18, 2003
Posts: 1
This error will happen if your connection or statement object gets closed before returning the resultset.
So, don't close the connection before returning the resultset. Write separate method in your bean to close the connection.
So, after calling the method which retrieve the resultset, then call the method to close the connection.
Also one more alternative is instead of returning the resultset, create objects using the resultset and store those objects in vector . Then you can return that vector object and use that. This approach is very much recommended.
sumana ar

Joined: Aug 06, 2003
Posts: 28
thanks for those suggessions..
as far as closing the resultset ..i'm calling another method which closes the conneciton. so this method is diferent from the one which returns the resultset..
but guys...after making some minor changes the problem is solved..
once again thanks for the help..
I agree. Here's the link:
subject: ResultSet is closed??
jQuery in Action, 3rd edition