For those who want to delve deeply into Java, this article continues our exploration of Java Database Connectivity (JDBC), examines JDBC drivers, and introduces you to using XML. The second of three parts, it is excerpted from chapter 20 of the book Sams Teach Yourself Java 2 in 21 Days, 4th Edition, written by Rogers Cadenhead and Laura Lemay (Sams; ISBN: 0672326280).
The default behavior of resultsets permits one trip through the set using its next() method to retrieve each record.
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
beforeFirst()—Moves to a place immediately before the first record in the set
first()—Moves to the first record in the set
last()—Moves to the last record in the set
previous()—Moves to the previous record in the set
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:
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: