Java Reference
In-Depth Information
able. The other concurrency type is ResultSet.CONCUR_UPDATABLE , which sig-
nifies an updatable ResultSet object.
In the solution to this recipe, a PreparedStatement object is used, and the
code to create a PreparedStatement object that has the ability to generate a scrol-
lable ResultSet looks like the following line:
pstmt = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
Once the PreparedStatement has been created as such, a scrollable Res-
ultSet is returned. You can traverse in several directions using a scrollable Res-
ultSet by calling the ResultSet methods indicating the direction you want to
move or the placement that you want to be. The following line of code will retrieve the
first record within the ResultSet :
ResultSet rs = pstmt.executeQuery();
rs.first();
The solution to this recipe demonstrates a few different scroll directions. Specific-
ally, you can see that the ResultSet first(), next(), last() , and pre-
vious() methods are called in order to move to different positions within the Res-
ultSet . For a complete reference to the ResultSet object, see the online docu-
mentation that can be found at http://docs.oracle.com/javase/8/docs/
api/java/sql/ResultSet.html .
Scrollable ResultSet objects have a niche in application development. They are
one of those niceties that are there when you need them, but they are also something
that you might not need very often.
13-9. Creating an Updatable ResultSet
Problem
Search WWH ::




Custom Search