Вопрос

from this java tutorial:

A RowSet object is scrollable and updatable by default, so by populating a RowSet object with the contents of a result set, you can effectively make the result set scrollable and updatable.

and then from this subsequent java tutorial:

Passing ResultSet Objects

The simplest way to create a JdbcRowSet object is to produce a ResultSet object and pass it to the JdbcRowSetImpl constructor. Doing this not only creates a JdbcRowSet object but also populates it with the data in the ResultSet object.

Note: The ResultSet object that is passed to the JdbcRowSetImpl constructor must be scrollable.

Why the result set needs to be scrollable if a RowSet object is scrollable by default? Is not that the main advantadge of wrapping a ResultSet in a JdbcRowSet?

UPDATE: Referring directly to the JdbcRowSet interface:

*One of the main uses of a JdbcRowSet object is to make a ResultSet object scrollable and updatable when it does not otherwise have those capabilities. *

quote from the same link.

Thanks in advance.

Это было полезно?

Решение

JdbcRowSetImpl is a - relatively - thin wrapper around a Resultset, so it demands that the ResultSet is also scrollable to be able to provide the required scrollability, if you don't want to or can't provide a scrollable result set you can use a CachedRowSet.

Contrary to what the tutorial you link to says, the com.sun.rowset.JdbcRowSetImpl does not convert a non-scrollable ResultSet to a scrollable result set. The implementation simply wraps the ResultSet and forwards calls directly to it, so if the ResultSet is not scrollable then the JdbcRowSet isn't either. Same goes for the updatability.

The tutorial seems to be contradictory, because after the introduction that you can use JdbcRowSet to make a result set scrollable, it notes:

A JdbcRowSet object created with a ResultSet object serves as a wrapper for the ResultSet object. Because the RowSet object rs is scrollable and updatable, jdbcRs is also scrollable and updatable. If you have run the method createStatement without any arguments, rs would not be scrollable or updatable, and neither would jdbcRs.

(emphasis mine)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top