Difference between ResultSet TYPE_SCROLL_SENSITIVE and TYPE_SCROLL_INSENSITIVE

I am trying to understand the difference between these two methods of creating an instruction:

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);

      

the second argument is the same, but the first is different

from java doc:

resultSetType

- type of result set; one of ResultSet.TYPE_FORWARD_ONLY

, ResultSet.TYPE_SCROLL_INSENSITIVE

orResultSet.TYPE_SCROLL_SENSITIVE

and

TYPE_SCROLL_INSENSITIVE


A constant that indicates the type of object ResultSet

that is scrolling, but is usually not sensitive to changes in the underlying data ResultSet

.


TYPE_SCROLL_SENSITIVE


A constant that specifies the type of object ResultSet

that scrolls, and is usually sensitive to changes in the underlying data ResultSet

.

Thus, I want to show the difference between the underlying sensitivity ResultSet

. I want to understand what is meant by "sensitive to underlying data changes ResultSet

" (from Javadoc).

Please provide an example to demonstrate and explain the difference.

+3


source to share


1 answer


Sensitivity refers to the underlying data (database).

Suppose you have a PEOPLE table in your database. You create an insensitive statement:

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

      

and at 8:20 am you issue a request

SELECT * FROM PEOPLE;

      



now you will leave the result set open and loop through using the next (), previous () and absolute (int)) methods.

At 8:23 am, someone is updating the data in the PEOPLE table.

At 8:24 am, you are still looping through the result set, but since you have an INSENSITIVE result set, you see the old data.

Now comes the difference. If you created the instruction with SENSITIVE, you will see all the changes that were made at 8:23.

+2


source







All Articles