gpt4 book ai didi

java - RowSet 对象默认可滚动吗?

转载 作者:行者123 更新时间:2023-11-30 04:20:46 26 4
gpt4 key购买 nike

来自this java教程:

A RowSet object is scrollable and updatable by default, so by populating a RowSet object with the contents of a result set, you can effectively make the result set scrollable and updatable.

然后从 this subsequent java教程:

Passing ResultSet Objects

The simplest way to create a JdbcRowSet object is to produce a ResultSet object and pass it to the JdbcRowSetImpl constructor. Doing this not only creates a JdbcRowSet object but also populates it with the data in the ResultSet object.

Note: The ResultSet object that is passed to the JdbcRowSetImpl constructor must be scrollable.

如果 RowSet 对象默认是可滚动的,为什么结果集需要可滚动?这不是将 ResultSet 包装在 JdbcRowSet 中的主要优点吗?

更新:直接引用 JdbcRowSet 接口(interface):

*One of the main uses of a JdbcRowSet object is to make a ResultSet object scrollable and updatable when it does not otherwise have those capabilities. *

引自同一个link .

提前致谢。

最佳答案

JdbcRowSetImpl 是一个相对较薄的 Resultset 包装器,因此它要求 ResultSet 也是可滚动的,以便能够提供所需的可滚动性,如果您不想或无法提供可滚动的结果集,您可以使用 CachedRowSet

与您链接到的教程所说的相反,com.sun.rowset.JdbcRowSetImpl不会将不可滚动的 ResultSet 转换为可滚动的结果集。该实现只是包装 ResultSet 并将调用直接转发给它,因此如果 ResultSet 不可滚动,则 JdbcRowSet 也不可滚动。可更新性也是如此。

该教程似乎很矛盾,因为在介绍可以使用 JdbcRowSet 使结果集可滚动之后,它指出:

A JdbcRowSet object created with a ResultSet object serves as a wrapper for the ResultSet object. Because the RowSet object rs is scrollable and updatable, jdbcRs is also scrollable and updatable. If you have run the method createStatement without any arguments, rs would not be scrollable or updatable, and neither would jdbcRs.

(强调我的)

关于java - RowSet 对象默认可滚动吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17121416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com