以下站点显示了在JDBC中使用新的AutoClosable功能:链接。此站点显示了Statement将如何自动关闭,但结果集不在try()部分中,它将自动关闭。所以,我的问题是,我不需要直接在Java 7中关闭ResultSet吗?我一直使用模式:关闭结果集,关闭语句,关闭连接。
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.
推荐答案来自 ResultSet的.Javadoc :
当生成它的Statement对象关闭,重新执行或用于从多个结果序列中检索下一个结果时,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.
更多推荐
在Java 7中关闭ResultSet
发布评论