Using a RowSet
Figure 24.29 reimplements the example of Fig. 24.23 using a RowSet. Rather than establish the connection and create a Statement explicitly, Fig. 24.29 uses a JdbcRowSet object to create a Connection and a Statement automatically.
Class RowSetProvider (package javax.sql.rowset) provides static method newFactory which returns a an object that implements interface RowSetFactory (package javax.sql.rowset) that can be used to create various types of RowSets. Lines 18–19 in the try-with-resources statement use RowSetFactory method createJdbcRowSet to obtain a JdbcRowSet object.
Lines 22–24 set the RowSet properties that the DriverManager uses to establish a database connection. Line 22 invokes JdbcRowSet method setUrl to specify the ...
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