Forums Register Login

Operation Not allowed after resultset is closed and I haven't closed it yet

+Pie Number of slices to send: Send
Hi all. I am trying to write a code in which i want to manage stock by fetching data from purchase table. I have the following code and it gave me Operation Not allowed after resultset is closed. I haven't closed it at all!. Please help!

+Pie Number of slices to send: Send
Please post the stack trace that you get with this error and show us on what line the exception occurs.

(also, moving this to JDBC forum)
+Pie Number of slices to send: Send
Where is your resultset declared?
Is this a multi-threaded environment?
Where is it closed?
+Pie Number of slices to send: Send
Thanks a ton for your kind reply!
Here's the full stacktrace



and here is the connection file where ResultSet is declared

+Pie Number of slices to send: Send
That's the connection, not the ResultSet.

Where is the ResultSet closed?
+Pie Number of slices to send: Send
Hi Pranit,
In JDBC a ResultSet associated with a Statement is closed as soon as we associate another ResultSet to the same Statement before closing the previous ResultSet.
I hope now you understand the problem in the code and find a solution and please post the solution if you get.
If you do not understand the problem even now we will provide the solution.
+Pie Number of slices to send: Send
 

Tapas Chand wrote:Hi Pranit,
In JDBC a ResultSet associated with a Statement is closed as soon as we associate another ResultSet to the same Statement before closing the previous ResultSet.
I hope now you understand the problem in the code and find a solution and please post the solution if you get.
If you do not understand the problem even now we will provide the solution.



Yes got that! Thanks a ton Tapas!
+Pie Number of slices to send: Send
Please post your solution.

On a separate note, the following things will make the program a little better.
1. You are using just 2 fields from your first ResultSet. So do not select all the fields, only select required fields. This will improve network traffic.
2. No need to call ResultSet.beforeFirst() before calling ResultSet.next(). Program will behave the same if you do not call ResultSet.beforeFirst() in this case.
3. In second ResultSet, I assume, you are expecting only 1 record from DB. If so, use if statement in place of while loop.
+Pie Number of slices to send: Send
4. I'm pretty sure that could be done as a single query.

You seem to be getting data back that is simply turned around back into the second query

Oh, and use a PreparedStatement rather than concatenating your query together.
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1295 times.
Similar Threads
update query doesn't run?
nested ResultSets
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException
myResultSet.beforeFirst()
Resultset
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:38:57.