在Java 7中关闭ResultSet

编程入门 行业动态 更新时间:2024-10-20 16:18:43
本文介绍了在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

本文发布于:2023-10-18 10:59:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504041.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Java   ResultSet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!