Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet is closed??

 
sumana ar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic