Which creates a connected RowSet object?
A. WebRowSet wrs = RowSetProvider.newFactory().createWebRowSet();
B. CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
C. try(JdbcRowSet jrs = RowSetProvider.newFactory().createJdbcRowSet()) {
// assume the rest of the try-catch is valid
D. try(RowSetFactory rsf = RowSetProvider.newFactory()) {
RowSet rws = rsf.createRowSet();
// assume the rest of the try-catch is valid
E. JoinRowSet jrs = RowSetProvider.newFactory().createJoinRowSet();
F. ResultSet rs = Statement.execute("SELECT * FROM Customer");
JdbcRowSet jrs = RowSetProvider.newFactory().setResultSet(rs);
Ans :
☑ C is the correct answer. This code fragment is creating an instance of a JdbcRowSet
object—the only RowSet that is a connected RowSet object. This is the proper way to use the
RowSetProvider static newFactory() method or obtain a RowSetFactory instance that is
then used to create a JdbcRowSet instance.
☐✗ A, B, and E are incorrect. These are disconnected RowSet objects, although the syntax
to acquire these objects is correct. D is incorrect and will not compile. The reason is that
RowSetFactory does not extend AutoCloseable; thus, the compiler will complain about the
use of RowSetFactory in a try-with-resources. F is incorrect because this is not the proper way
to initialize a RowSet object. The factory method is used to create an instance, and the instance
must be used to execute a query and populate the RowSet with results.
Question
Why A,B,E are incorrect?How they are Disconnected RowSet Object?