JDBC garbage collection

前端 未结 5 803
傲寒
傲寒 2020-12-19 20:26

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

5条回答
  •  执念已碎
    2020-12-19 20:54

    You must explicitly close the ResultSet and Statement objects after you finish using them. This applies to all ResultSet and Statement objects you create when using the JDBC drivers. The drivers do not have finalizer methods; cleanup routines are performed by the close() method of the ResultSet and Statement classes. If you do not explicitly close your ResultSet and Statement objects, serious memory leaks could occur. You could also run out of cursors in the database. Closing both the result set and the statement releases the corresponding cursor in the database; if you close only the result set, the cursor is not released

提交回复
热议问题