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 RowSet
s. 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 ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.