有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在ResultSet类型_SCROLL _SENSITIVE和类型_SCROLL _SENSITIVE之间的差异

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

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)的基础数据的更改敏感”是什么意思

请提供一个例子来说明这种差异


共 (1) 个答案

  1. # 1 楼答案

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

    假设数据库中有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时,您仍在滚动结果集,但因为您有不敏感的结果集,所以会看到旧数据

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