Java Reference
In-Depth Information
By changing how statements and prepared statements are created, you can produce
resultsets that support these additional methods:
afterLast() —Moves to a place immediately after the last record in the set
n
beforeFirst() —Moves to a place immediately before the first record in the set
n
first() —Moves to the first record in the set
n
last() —Moves to the last record in the set
n
previous() —Moves to the previous record in the set
n
These actions are possible when the resultset's policies have been specified as arguments
to a database connection's createStatement() and prepareStatement() methods.
Normally, createStatement() takes no arguments, as in this example:
Connection payday = DriverManager.getConnection(
“jdbc:odbc:Payroll”, “Doc”, “1rover1”);
Statement lookSee = payday.CreateStatement();
For a more flexible resultset, call createStatement() with three integer arguments that
set up how it can be used. Here's a rewrite of the preceding statement:
Statement lookSee = payday.CreateStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY,
ResultSet.CLOSE_CURSORS_AT_COMMIT);
The same three arguments can be used in the prepareStatement( String, int, int,
int ) method after the text of the statement.
The ResultSet class includes other class variables that offer more options in how sets
can be read and modified.
JDBC Drivers
Creating a Java program that uses a JDBC driver is similar to creating one that uses the
JDBC-ODBC bridge.
Java 6 includes the Java DB relational database, which is built from the open source
Apache Derby database, and comes with its own driver. For more sophisticated data-
bases, more than a dozen companies, including Informix, Oracle, Symantec, IBM, and
Sybase, sell drivers or package them with commercial products. A database of available
JDBC drivers can be found on Sun's JDBC site at http://developers.sun.com/product/
jdbc/drivers.
Search WWH ::




Custom Search