I'd like to pass out a result set from a function that executes a query and closes the connection.
But the ResultSet gets invalidated as soon as its parent Connection is closed and throws
java.sql.SQLException: Operation not allowed after ResultSet closed
How to avoid this?
You can't. If you want to get all the data, loop the ResultSet and insert the data into a collection of yours.
Take a look at commons-dbutils - it has a lot of useful helpers.
Also consider using a disconnected result set: CachedRowSet. Quick googling gave me this: Using CachedRowSet to Transfer JDBC Query Results Between Classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With