java ResultSet TYPE_SCROLL_SENSITIVE 和 TYPE_SCROLL_INSENSITIVE 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25585218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between ResultSet TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE
提问by gstackoverflow
I am trying to understand the difference between these two methods of creating a statement:
我试图了解这两种创建语句的方法之间的区别:
1:
1:
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
2:
2:
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
second argument are same but first - different
第二个参数相同,但第一个参数不同
from java doc:
来自 java 文档:
resultSetType
- a result set type; one ofResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
, orResultSet.TYPE_SCROLL_SENSITIVE
resultSetType
- 结果集类型;中的一个ResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
或ResultSet.TYPE_SCROLL_SENSITIVE
and
和
TYPE_SCROLL_INSENSITIVE
The constant indicating the type for aResultSet
object that is scrollable but generally not sensitive to changes to the data that underlies theResultSet
.
TYPE_SCROLL_INSENSITIVE
指示ResultSet
可滚动的对象类型的常量,但通常对ResultSet
.
TYPE_SCROLL_SENSITIVE
The constant indicating the type for aResultSet
object that is scrollable and generally sensitive to changes to the data that underlies theResultSet
.
TYPE_SCROLL_SENSITIVE
指示ResultSet
可滚动对象的类型的常量,并且通常对ResultSet
.
Thus I want to show difference between sensitivity of underlies the ResultSet
. I want to understand what this "sensitive to changes to the data that underlies the ResultSet
" (from Javadoc) means.
因此,我想展示ResultSet
. 我想了解这个“对底层数据更改敏感ResultSet
”(来自 Javadoc)是什么意思。
Please provide an example that demonstrates and explains the difference.
请提供一个示例来演示和解释差异。
回答by Filip Nguyen
Sensitivness is with regards to the underlying data (a database).
敏感性与基础数据(数据库)有关。
Suppose you have PEOPLE table in a database. You create insensitive statement:
假设您在数据库中有 PEOPLE 表。您创建不敏感的语句:
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
and at time 8:20 you issue a query
并且在 8:20 你发出一个查询
SELECT * FROM PEOPLE;
now you leave the result set open and you scroll through it using next(), previous() and absolute(int)) methods.
现在您将结果集保持打开状态,并使用 next()、previous() 和 absolute(int)) 方法滚动浏览它。
At 8:23 somebody updates data in PEOPLE table.
8:23 有人更新了 PEOPLE 表中的数据。
At 8:24 you are still scrolling the result set but because you have INSENSITIVE result set, you see old data.
在 8:24,您仍在滚动结果集,但由于您有 INSENSITIVE 结果集,您会看到旧数据。
Now comes the difference. If you had created the statement with SENSITIVE then you would see all the changes that were being done at 8:23.
现在区别来了。如果您使用 SENSITIVE 创建了语句,那么您将看到在 8:23 进行的所有更改。