Consequences of Not Closing ResultSet in JDBC
Fast recall
Quick revision
Core answer
Whether you know unclosed ResultSets leak cursors and the try-with-resources fix.
Relying on Statement/Connection close or GC to clean up the ResultSet.
Note closing the Statement closes its ResultSet, but explicit try-with-resources is clearest.
Interview-ready guide
Interview answer
A query that streams millions of rows may keep the statement and connection busy until the result is consumed or closed. A small fully buffered result may not hold a server-side cursor, but its JDBC objects still need deterministic cleanup. Nest ResultSet and PreparedStatement inside the Connection's try-with-resources block so exceptions close them in reverse order.
Consequences of Not Closing ResultSet in JDBC
Direct Answer
A ResultSet can retain driver, statement, connection, memory, network, or database cursor resources until it is closed. Exact resources depend on the driver and result mode; it is not guaranteed that every ResultSet holds a server cursor. Failing to close results/statements can delay returning a pooled connection and eventually cause resource exhaustion. Use try-with-resources.
Common Mistakes & Pitfalls
Relying on Statement/Connection close or GC to clean up the ResultSet.
Check your understanding
Answer these without looking back at the article.
- What is a ResultSet in JDBC and how do you iterate it?
- How do you check for NULL values when reading from a ResultSet?
- How do you map ResultSet rows to Java objects in JDBC?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.