Skip to content
Advertisement

How can I avoid ResultSet is closed exception in Java?

As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it?

EDIT: I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue?

Advertisement

Answer

Sounds like you executed another statement in the same connection before traversing the result set from the first statement. If you’re nesting the processing of two result sets from the same database, you’re doing something wrong. The combination of those sets should be done on the database side.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement