Java Reference
In-Depth Information
Some database management systems, such as Oracle, get around this by letting you
use fully qualified columns names of the form table_na me.column_name to resolve
this situation; but others, such as MSAccess, do not, so if there are multiple columns
with the same name, using the column index is more portable. It may also be slightly
more efficient to use column numbers.
Caution Column values should be read only once. Subsequent reads are not
guaranteed to return valid data.
Scrollable ResultSets
One of the features added in the JDBC 2.0 API is the ScrollableResultSet, which
supports the ability to move a result set's cursor in either direction. In addition to
methods that move the cursor backwards and forwards, there are methods for getting
the cursor position and moving the cursor to a particular row.
Creating a Scrollable ResultSet
The type of ResultSet a java.sql.Statement object returns is defined when the
Statement is created by the Connection.createStatement method. These are the two
forms of the Connection.createStatement method:
public Statement createStatement () throws SQLException
public Statement createStatement (int rsType, int rsConcurrency) throws
SQLException
The first of these methods is discussed in the examples earlier in this chapter. The
second variant allows the user to create scrollable and updateable ResultSets.
The first argument, rsType, must be one of the three following constants added to the
ResultSet interface to indicate the type of a ResultSet object:
 
TYPE_FORWARD_ONLY
 
TYPE_SCROLL_INSENSITIVE
 
TYPE_SCROLL_SENSITIVE
Specifying the constant TYPE _ FORWARD _ ONLY creates a nonscrollable result set
(that is, one i n which the cursor moves forward only). If you also specify
CONCUR_READ_ONLY for the second argument, you will get the default ResultSet
identical to the ResultSet created with the no-argument variant.
To get a scrollable ResultSet object, you must specify either
TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE. The difference
between these two types of scrollable result sets is that a result set defined using
TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open,
and one that is TYPE_SCROLL_SENSITIVE does. Of course, you can always see
Search WWH ::




Custom Search