Hi Friends, I have two queries to run from one class.I send the queries to another class,which send me back the resultset to cook.For one query its running fine,but i don't know why for two queries ,its throwing error as "statement closed".Can you please tell me where i am going wrong???
In first method i have: ResSet qt = new ResSet(); ResultSet rs=qt.getResultSet(query);
2nd method: ResSet qt1 = new ResSet(); ResultSet rs1=qt1.getResultSet(query1);
The error means you are probable closing your statement too early. As, i don't know where you're closing it, only thing i can tell is to check where you're using your close() method to close your statement(it should be at the end of everything since you have included statement, resultset and connection in that method).
Hi, The code is pretty odd, but let me take a shot at it I think first time around you somehow have a valid handle to the datasource (maybe you call getResults()), and as ds!=null, you get a new connection, create statement and hence everything works fine. But looks like from what you have posted you dont close the connection or statement or resultset (or do you call close() from the calling class?). Whatever be the case, second time you dont seem to have a valid handle to datasource, and the line results = st.executeQuery(Query); runs irrespective of state of data source. You will have to handle the case if ds is null, if so you have to call getResults() to get data source
(Also why do you have con.close(); in the getResults() method? And you might want to call getResults() as getDataSource() for clarity)
Joined: Jan 16, 2005
Thanks friends, I am calling the close() method from my jsp page,after I have finished with all my processing.I don't know why it's throwing the error..can you give me any other clue that might help.
Joined: Jan 16, 2005
Padma, I've removed the con.close() method from getResultSet() and i also removed the close() call from my jsp,which calls the close() method in the calling class,which calls the close() method in this class.
Whatever be the case, second time you dont seem to have a valid handle to datasource, and the line results = st.executeQuery(Query); runs irrespective of state of data source. You will have to handle the case if ds is null, if so you have to call getResults() to get data source
I think ,this might be the error,can you please tell me how to handle this??
Joined: Nov 02, 2004
Hi, You will need to add the close call back to the jsp, this will close the connection to the db after you are done with processing the results.
For you error, all you need to do is add a checking for if ds is null in the first line if(ds==null) ds= getResults(); and then continue the same code as before and please include results = st.executeQuery(Query); inside the check for valid connection. How can you run a statement if you dont have a connection? You need a statement to execute query, a connection to create statement & a data source to get connection from, so all steps must complete correctly to be able to run query
And of course this is a quick fix & not best way to do it. (you dont even have to do null checking as you are not persisting the object between method invocations, unless you are doing connection pooling which i dont see, so everyting will be null until initialized) Hope this helps, Padma