| Author |
ResultSet is closed??
|
sumana ar
Greenhorn
Joined: Aug 06, 2003
Posts: 28
|
|
hi, 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 end 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 closed...here exec is the method which returns the resultset what could be the problem..some one plz help me solve the problem.. thanks. --sumana
|
 |
Gayathri Prasad
Ranch Hand
Joined: Jun 25, 2003
Posts: 116
|
|
Hi Sumana, This might be of some help http://www.coderanch.com/t/295368/JDBC/java/ResultSet-closed-error Cheers, Gaya3 ----------------------------- Prasanna Kumar R.V
|
 |
sumana ar
Greenhorn
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. code: ---------------------------------------------------------------------------- Statement stmt1 = myConn.createStatement(); query = "update TransactEJBTable set comments = '" + request.getParameter(strIndex) + "' where ResId = '" + ResId + "' and RevId = '" + RevId + "'"; out.println(query); stmt1.execute(query); -------------------------------------------------------------- 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... --sumana.
|
 |
swathi java
Greenhorn
Joined: Sep 18, 2003
Posts: 1
|
|
Hi, 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
Greenhorn
Joined: Aug 06, 2003
Posts: 28
|
|
hi, 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.. --sumana
|
 |
 |
|
|
subject: ResultSet is closed??
|
|
|