gpt4 book ai didi

java - 结果集 TYPE_SCROLL_SENSITIVE 和 TYPE_SCROLL_INSENSITIVE 之间的区别

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:20:23 24 4
gpt4 key购买 nike

我试图了解这两种创建语句的方法之间的区别:

1:

Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

2:

Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

第二个参数相同但第一个参数不同

来自 java 文档:

resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

TYPE_SCROLL_INSENSITIVE
The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.


TYPE_SCROLL_SENSITIVE
The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet.

因此,我想展示 ResultSet 底层的敏感性之间的差异。我想了解“对 ResultSet 下的数据变化敏感”(来自 Javadoc)是什么意思。

请提供一个示例来说明和解释差异。

最佳答案

敏感性与基础数据(数据库)有关。

假设您在数据库中有 PEOPLE 表。您创建不敏感的声明:

Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

在时间 8:20 你发出了一个查询

SELECT * FROM PEOPLE;

现在让结果集保持打开状态,然后使用 next()、previous() 和 absolute(int)) 方法滚动浏览它。

8:23 有人更新了 PEOPLE 表中的数据。

在 8:24,您仍在滚动结果集,但因为您有 INSENSITIVE 结果集,所以您看到的是旧数据。

现在不同了。如果您使用 SENSITIVE 创建语句,那么您将看到在 8:23 进行的所有更改。

关于java - 结果集 TYPE_SCROLL_SENSITIVE 和 TYPE_SCROLL_INSENSITIVE 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25585218/

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