What happens if i don\'t close resultset or preparedstatements.
Will they be closed and released by the garbage collector.
I\'m asking this for local variabl
-> What happens if i don't close resultset or preparedstatements? Will they be closed and released by the garbage collector?.
That way you are degrading the database and application performance. You must have to close or dispose JDBC resource properly.
To close or dispose
(JDBC resource) objects means these objects are now available for garbage collection and GC will releases any JDBC
resources which had been acquired.
In case of ResultSet
object, it will be closed automatically when Statement.close()
method is called. You may call ResultSet.close() method if you want to close ResultSet
object explicitly (Read Article - 5.1.20 Closing a ResultSet Object).
Have a look at articles - Best Practice: Closing and releasing JDBC resources and Enhancements in Java SE 7 and JDBC 4.1 (Text from this article - Feature: The ability to use a try-with-resources statement to automatically close resources of type Connection, ResultSet, and Statement)