Implementations of RowSet, CachedRowSet etc

后端 未结 4 1691
栀梦
栀梦 2020-12-09 04:46

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 ser

相关标签:
4条回答
  • 2020-12-09 05:02

    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:

    • JDBC Guide - Chapter 10 - RowSet
    • JDBC RowSet tutorial, by Oracle
    • Java 8 javax.sql.rowset package summary
    • Source code in OpenJDK 8 for Oracle’s com.sun.rowset implementation, Gnu GPL 2 license with Classpath exception
    0 讨论(0)
  • 2020-12-09 05:07

    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.

    0 讨论(0)
  • 2020-12-09 05:14

    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.

    0 讨论(0)
  • 2020-12-09 05:17

    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

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题