在Java 7中关闭ResultSet [英] Closing ResultSet in Java 7

查看:369
本文介绍了在Java 7中关闭ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下站点显示了在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆