Getting java.sql.SQLException: Operation not allowed after ResultSet closed

The problem is with the way you fetch data in getStuff(). Each time you visit getStuff() you obtain a fresh ResultSet but you don’t close it.

This violates the expectation of the Statement class (see here – http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html):

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment’s current ResultSet object if an open one exists.

What makes things even worse is the rs from the calling code. It is also derived off-of the statement field but it is not closed.

Bottom line: you have several ResultSet pertaining to the same Statement object concurrently opened.

Leave a Comment