Java Reference
In-Depth Information
while (results.previous())
//Iterate through rows in reverse direction,
//again displaying contents of each row…
showRow();
}
catch(SQLException sqlEx)
{
System.out.println(
"* Error retrieving data! *");
sqlEx.printStackTrace();
System.exit(1);
}
try
{
connection.close();
}
catch(SQLException sqlEx)
{
System.out.println(
"* Unable to disconnect! *");
sqlEx.printStackTrace();
}
}
public static void showRow() throws SQLException
{
System.out.println();
System.out.println("Account no. "
+ results.getInt(1));
System.out.println("Account holder: "
+ results.getString(3)
+ " " + results.getString(2));
System.out.printf("Balance: %.2f %n%n",
results.getFloat(4));
}
}
The output from this program is shown in Fig.
7.5
. For some reason, the initial
ordering of rows when using the second version of method
createStatement
differs
from that which occurs with the original version of
createStatement
(even though
exactly the same query is used and movement through the data rows is in the
forward direction in both cases). However, it can clearly be seen that the order of
output when
previous
is used is the reverse of that which occurs in this program
when
next
is used.
Search WWH ::
Custom Search