♠ Posted by Unknown in Adv Java at 01:44
JDBC Resultsets
Before JDBC 2.1, a ResultSet object created by
executing a statement was, by default, forward-only scrollable. That is, we
could traversse through the resultset using the next() method only. next()
returns false when the last record is reached, and no more details can then be
retrieved.
The JDBC 2.1 API (included in the J2SE 1.2 onwards)
provides more flexible means of accessing results from ResultSet objects. These
enhancement are categorized into the following:
- Scrollable
resultsets :
The JDBC 2.1 ResultSet objects are scrollable
resultsets have the ability to move the cursor backwards, and also support
absolute positioning of the cursor at a particular row in the4 resultset.
The java.sql.ResultSet interface specifies three types
of resultsets:
1. TYPE_FORWARD_ONLY – A resultset of this type
supports forward-scrolling only.
2. TYPE_SCROLL_INSENSITIVE – A resultset of this
type supports scrolling in both directions.
3. TYPE_SCROLL_SENSITIVE – A resultset of this type
is sensitive to updates made to the data after the resultset has been
populated. For instance, if your query returns 10 rows, and if another
application removes two of the rows, your resultset will only have 8 rows. The
same happens for inserts/updates too.
- Scroll
sensitivity :
The JDBC 2.1 APT also specifies scroll-sensitive and
scroll-insensitive resultsets. A scroll insensitive resultset represents a
static snapshot of the results when the query was made. On the other hand, a
scroll-sensitive resultset is sensitive to changes made to the data after the
query has been executed, thus providing a dynamic view of the data as it
changes.
- Updatable
resultsets :
By default, resultsets are read-only. That is,
contents of the resultset are read-only and connot be changed. The JDBC 2.1 API
also introduces updateable resultsets. When a resultset is updated, the update
operation also updates the original data corresponding to the resultset.
The java.sql.ResultSet interface specifies two
constants to indicate whether the resultset is read-only of updateable:
0 comments:
Post a Comment