Scrollable Result Sets
The single most visible addition to the JDBC API in its 2.0 specification is support for scrollable result sets. When the JDBC specification was first finalized, the specification contributors engaged in serious debate as to whether or not result sets should be scrollable. Those against scrollable result sets—and I was one of them—argued that they were antithetical to object-oriented programming and that they violated the rule that complex functionality should not encumber the most commonly used classes. In addition, requiring all driver vendors to implement scrollable result sets could adversely impact the performance of more mundane result set operations for some database engines. Scrollable result sets, on the other hand, are common in database vendor APIs, and the database vendors thus believed they should be present in JDBC.
Result Set Types
Using scrollable
result sets starts with the way in which you create statements.
Earlier in the chapter, you learned to create a statement using the
createStatement( ) method. The Connection class actually
has two versions of createStatement()—the
zero parameter version you have used so far and a two parameter
version that supports the creation of Statement
instances that generate scrollable ResultSet
objects. The default call translates to the following call:
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);The first argument is the result set type. The value
ResultSet.TYPE_FORWARD_ONLY ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access