Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Tim Cooke
Sheriff
Pie
Posts: 3209
142
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Dave Tolls
Ranch Hand
Posts: 2110
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your resultset declared?
Is this a multi-threaded environment?
Where is it closed?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton for your kind reply!
Here's the full stacktrace



and here is the connection file where ResultSet is declared

 
Dave Tolls
Ranch Hand
Posts: 2110
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the connection, not the ResultSet.

Where is the ResultSet closed?
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Tolls
Ranch Hand
Posts: 2110
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic