1.1.1

Table Of Contents
stmt.close();
// Close connection if the application does not need it any
more
conn.close();
Scrollable Insensitive Result Sets
JDBC provides two types of result sets that allow you to scroll in either direction or to move the cursor to a
particular row. SQLFire supports one of these types: scrollable insensitive result sets
(ResultSet.TYPE_SCROLL_INSENSITIVE).
When you use a result set of type of type ResultSet.TYPE_SCROLL_INSENSITIVE, SQLFire materializes
rows from the rst one in the result set up to the one with the biggest row number as the rows are requested. The
materialized rows are backed to disk if necessary, to avoid excessive memory usage.
Insensitive result sets, in contrast to sensitive result sets, cannot see changes made by others on the rows that
have materialized. SQLFire allows updates of scrollable insensitive result sets, as described in Visibility of
Changes on page 178. (SQLFire also allows updates of forward-only result sets.)
Note: SQLFire does not support result sets of type ResultSet.TYPE_SCROLL_SENSITIVE.
//autocommit does not have to be off because even if
//we accidentally scroll past the last row, the implicit commit
//on the the statement will not close the result set because result sets
//are held over commit by default
conn.setAutoCommit(false);
Statement s4 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
s4.execute("set schema 'SAMP'");
ResultSet scroller=s4.executeQuery(
"SELECT sales_person, region, sales FROM sales " +
"WHERE sales > 8 ORDER BY sales DESC");
if (scroller.first()) { // One row is now materialized
System.out.println("The sales rep who sold the highest number" +
" of sales is " +
scroller.getString("SALES_PERSON"));
} else {
System.out.println("There are no rows.");
}
scroller.beforeFirst();
scroller.afterLast(); // By calling afterlast(), all rows will be
materialized
scroller.absolute(3);
if (!scroller.isAfterLast()) {
System.out.println("The employee with the third highest number " +
"of sales is " +
scroller.getString("SALES_PERSON") + ", with " +
scroller.getInt("SALES") + " sales");
}
if (scroller.isLast()) {
System.out.println("There are only three rows.");
}
if (scroller.last()) {
System.out.println("The least highest number " +
"of sales of the top three sales is: " +
scroller.getInt("SALES"));
181
Using Result Sets and Cursors