Sunday, February 28, 2016

ResultSet--Types and Concurrency

Type of ResultSet

ResultSet can be of three types. If you do not specify any ResultSet type, you will automatically get one that is TYPE_FORWARD_ONLY.
TypeDescription
ResultSet.TYPE_FORWARD_ONLYThe cursor can only move forward in the result set.
ResultSet.TYPE_SCROLL_INSENSITIVEThe cursor can scroll forward and backward, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.
ResultSet.TYPE_SCROLL_SENSITIVE.The cursor can scroll forward and backward, and the result set is sensitive to changes made by others to the database that occur after the result set was created.

Concurrency of ResultSet

The possible RSConcurrency are given below. If you do not specify any Concurrency type, you will automatically get one that is CONCUR_READ_ONLY.
ConcurrencyDescription
ResultSet.CONCUR_READ_ONLYCreates a read-only result set. This is the default
ResultSet.CONCUR_UPDATABLECreates an updateable result set.
All our examples written so far can be written as follows, which initializes a Statement object to create a forward-only, read only ResultSet object −
try {
   Statement stmt = conn.createStatement(
                           ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex) {
   ....
}
finally {
   ....
}

Concurrency of ResultSet

If you do not specify any Concurrency type, you will automatically get one that is CONCUR_READ_ONLY.
ConcurrencyDescription
ResultSet.CONCUR_READ_ONLYCreates a read-only result set. This is the default
ResultSet.CONCUR_UPDATABLECreates an updateable result set.
All our examples written so far can be written as follows, which initializes a Statement object to create a forward-only, read only ResultSet object −
try {
   Statement stmt = conn.createStatement(
                           ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex) {
   ....
}
finally {
   ....
}