How to prevent a ResultSet from being invalidated on Connection close?

database-connection, java, jdbc, resultset, scala

Solution

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.

Problem

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?

Original source