The following site shows using the new "AutoClosable" features with JDBC: link. This site is showing how the Statement will be automatically closed, but the result set is not in the try() section where it would be auto-closed. So, my question is, do I NOT need to close ResultSets directly in Java 7? I have always used the pattern: close resultset, close statement, close connection.
Asked
Active
Viewed 3,939 times
7
-
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html – Kanagavelu Sugumar May 11 '16 at 16:38
1 Answers
15
From the Javadoc of ResultSet:
A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.

Mark Rotteveel
- 100,966
- 191
- 140
- 197

Durandal
- 19,919
- 4
- 36
- 70
-
-
1BTW: ResultSets are also `AutoCloseable`, so there is nothing keeping you from using try-with-resources to close the resultset as soon as possible. – Mark Rotteveel Jul 12 '12 at 18:32