15

Until today I was working with ResultSet when handling results from queries. But today I read a little about RowSet and CachedRowset and I realized they can serve my purposes better. While in all the examples I read where RowSet and CachedRowSet were referred to as object, when I tried it myself in my code I realized those are interfaces and in the examples they use some implementation of those interfaces.

Now my question is where do I find those implementations, and is there something official?

Do I need to download them or do they come with the JDK?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Bennyz
  • 623
  • 2
  • 18
  • 36

4 Answers4

20

The implementations are JRE specific. Oracle (Sun) JRE comes with a bunch of implementations:

  • com.sun.rowset.JdbcRowSetImpl
  • com.sun.rowset.CachedRowSetImpl
  • com.sun.rowset.WebRowSetImpl
  • com.sun.rowset.FilteredRowSetImpl
  • com.sun.rowset.JoinRowSetImpl

In Java 1.6 and before, you'd need to construct them yourself:

JdbcRowSet rowSet = new JdbcRowSetImpl();
rowSet.setDataSourceName("jdbc/dbname");
// Or
rowSet.setUrl("jdbc:vendor://host:port/dbname");
rowSet.setUsername("username");
rowSet.setPassword("password");

rowSet.setCommand("SELECT id, name, value FROM tbl");
rowSet.execute();

while (rowSet.next()) {
    // ...
}

In Java 1.7 you can get them by a javax.sql.rowset factory so that you're not dependent of underlying JRE implementation and that you can finetune the implementation of choice if necessary:

RowSetFactory rowSetFactory = RowSetProvider.newFactory();
JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet();
// ...

It only doesn't provide a possibility to pass a ResultSet on construction. Those implementations doesn't ship with the average JDBC driver (at least, MySQL and PostgreSQL have none). It's basically an extra (optional) layer over JDBC API as the package name prefix javax hints.

Note that if you get that far by looking into rowsets, then you might want to consider to look into an ORM instead, such as Hibernate or JPA. They provide first/second level cache possibilities.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for the answer! I don't have all those Impl classes, do I need to download them? If I do, it makes things a little complicated. I'll be learning ORM later in my training, I've just stumbled upon RowSet, and I thought it'd be better to use it rather than ResultSet which requires an open connection. – Bennyz Nov 21 '11 at 20:50
  • They're present in the JRE/JRK. Perhaps you're using an IDE and it is suppressing the import of restricted API? It's configureable in IDE's preferences. – BalusC Nov 21 '11 at 20:52
  • I'm using Eclipse (Indigo) and I can only see com.sun.rowset.internal and com.sun.rowset.providers – Bennyz Nov 21 '11 at 21:00
  • Add this line: `import com.sun.rowset.JdbcRowSetImpl;` What does the warning/error message say? If it errors, then you can configure it by setting *Window > Preferences > Java > Errors/Warnings > Deprecated and restricted API > Forbidden reference* to *Ignore* or *Warning* instead of *Error*. – BalusC Nov 21 '11 at 21:01
  • Be aware that some JDBC drivers also provide an implementation of RowSet. – Basil Bourque Jul 14 '14 at 19:13
0

It comes with the JDK.

In JDK 10, the jar is: jdk-10.0.2/lib/jrt-fs.jar

And the package/class inside the jar is: javax.sql.RowSet.class

Daniel Pinheiro

danielpm1982@gmail.com

enter image description here

enter image description here

Daniel Pinheiro
  • 988
  • 8
  • 14
0

Add rt.jar in Eclipse Java Build Path. Then you see all the implemention class. Else you can remove the restriction from Eclipse which is not allowing to access rt.jar from jdk. Works for me. I was using jdk1.6 and Eclipse Luna.

Nizam
  • 573
  • 1
  • 5
  • 12
0

The RowSet and CachedRowSet are implemented by the JDBC drivers.

Your database provider delivers the drivers e.g. Oracle or MySql. However those drivers only make sense in conjunction with an actual database.

bluish
  • 26,356
  • 27
  • 122
  • 180
Udo Held
  • 12,314
  • 11
  • 67
  • 93
  • 1
    I have the ojdbc14.jar, but it doesn't contain oracle.jdbc.rowset which contains OracleCachedRowSet and all the others. Does it have anything to do with the version or something like that? – Bennyz Nov 21 '11 at 20:17
  • 1
    The ojdbc14.jar is a java 1.4 driver. The CachedRowSet was introduced with java 1.5. You need to get a JDBC 3.0 or higher driver. – Udo Held Nov 21 '11 at 20:47
  • 1
    True, a JDBC driver vendor may provide a RowSet implementation. But Sun/Oracle has also released source code for implementations under the [GNU General Public License version 2](http://www.gnu.org/licenses/gpl-2.0.html). – Basil Bourque Jun 03 '14 at 22:59
  • It was introduced in JDBC 3, Java 1.4. I have never seen a vendor implementation of `CachedRowSet` – user207421 Apr 08 '16 at 02:13
  • Dear Down-Voters: Please leave a criticism along with your vote. This Answer seems to me to be correct, valid, and valuable. – Basil Bourque May 12 '17 at 23:20
  • @EJP See the [Answer by BalusC](http://stackoverflow.com/a/8218122/642706) for links to an implementation by Sun and maintained by Oracle, bundled with their implementation of Java. See [this similar Question](http://stackoverflow.com/q/2228462/642706) for implementations specifically for MySQL and Firebird. – Basil Bourque May 12 '17 at 23:25