I am trying to understand the difference between these two methods of creating a statement:
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
second argument are same but first - different
from java doc:
resultSetType
- a result set type; one ofResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
, orResultSet.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_SENSITIVE
The constant indicating the type for aResultSet
object that is scrollable and generally sensitive to changes to the data that underlies theResultSet
.
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.
Please provide an example that demonstrates and explains the difference.
Sensitivness is with regards to the underlying data (a database).
Suppose you have PEOPLE table in a database. You create insensitive statement:
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
and at time 8:20 you issue a query
SELECT * FROM PEOPLE;
now you leave the result set open and you scroll through it using next(), previous() and absolute(int)) methods.
At 8:23 somebody updates data in PEOPLE table.
At 8:24 you are still scrolling the result set but because you have INSENSITIVE result set, you see old data.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With