• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ResultSet is closed??

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumana,
This might be of some help
https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic