Exploring JDBC and XML
(Page 1 of 4 )
Moving Through Resultsets
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.
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(
The same three arguments can be used in the
prepareStatement( method after the text of the statement. String, int, int, int)
ResultSet class includes other class variables that offer more options in how sets can be read and modified.