0

I've asked a question on how to retrieve data from ResultSet before closing the connections.

JDK Version: jdk1.8.0_201

CachedRowSet class is suggested in an answer by someone in the above mentioned question. I've tried going with that approach but got an exception when try to run the program.

java.sql.SQLException: Provider com.sun.rowset.RowSetFactoryImpl not found

As per my analysis, packages of com.sun are internal and are subjected to change. They should never be used except by JDK developers.

Suggest me something to resolve this.

Here is my code

/*--- Imports of classes---*/
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;
/*--- End of Imports ---*/

public ResultSet getUSStates() throws SQLException {
    _log.info("Calling stored proc for ocrt give data");

    try(Connection inGlobalConnections = getConnection();
        CallableStatement callableStatement = inGlobalConnections.prepareCall("{call mst.USP_GetUSStates()}");
        ResultSet resultSet = callableStatement.getResultSet();) {

        callableStatement.execute();

        CachedRowSet cachedRowSet = RowSetProvider.newFactory().createCachedRowSet();
        cachedRowSet.populate(resultSet);

        return cachedRowSet;
    } catch (Exception e) {
        _log.error(e, e);
    }

    return null;
}
  • 2
    Packages with `com.sun` are not necessarily internal (there are libraries out there that use the same prefix), it is packages with `sun.*` which are internal. In any case, it would be helpful to know your Java version, the Java vendor, and whether or not you have a `module-info.java`, and if so, what its contents are. – Mark Rotteveel Aug 30 '23 at 08:04
  • That said, the `com.sun.rowset.*` packages included in Java are considered "not-public" and should be accessed only through the `javax.sql.rowset.*` API. – Mark Rotteveel Aug 30 '23 at 08:10
  • @MarkRotteveel Apologies for the confusion, I've edited my question by adding JDK version. I don't know whether I'm right or not but `module-info.java` is not present in `jdk1.8.0_201 or earlier`. Please correct me if I am wrong. – Anubhav kalra Aug 30 '23 at 08:12
  • Why are you using such an old Java version? The latest Java 8 is Java 8 update 381/382. Also, which vendor, is this Oracle, AdoptOpenJDK/Eclipse Adoptium, Azul, some other JVM vendor? – Mark Rotteveel Aug 30 '23 at 08:12
  • @MarkRotteveel If I try with latest java 8 version, will this issue resolve? – Anubhav kalra Aug 30 '23 at 08:35
  • I don't know, try it, I'd say. – Mark Rotteveel Aug 30 '23 at 09:09
  • 1
    All I can say is that with Eclipse Adoptium Java 8 update 382, the line `RowSetProvider.newFactory().createCachedRowSet()` executes without an error and produces a rowset of type `com.sun.rowset.CachedRowSetImpl`. – Mark Rotteveel Aug 30 '23 at 11:55
  • Also, while `com.sun` classes are internal, it *is* being used internally here. Your code is not referring to any `com.sun` classes, only `javax.sql` classes. So that need not concern you. – David Conrad Aug 30 '23 at 15:26

0 Answers0