Reputation:
When migrating my project to Java 19, I am getting this error related to our use of RowSet:
cannot access class com.sun.rowset.CachedRowSetImpl (in module java.sql.rowset) because module java.sql.rowset does not export com.sun.rowset to module
and this is my code
import javax.sql.rowset.*;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.*;
import javax.sql.rowset.CachedRowSet;
public static ResultSet dbExecuteQuery(String queryStmt) throws SQLException, ClassNotFoundException {
//Declare statement, resultSet and CachedResultSet as null
Statement stmt = null;
ResultSet resultSet = null;
CachedRowSetImpl crs = null;
try {
//Connect to DB (Establish Oracle Connection)
dbConnect();
System.out.println("Select statement: " + queryStmt + "\n");
//Create statement
stmt = conn.createStatement();
//Execute select (query) operation
resultSet = stmt.executeQuery(queryStmt);
//CachedRowSet Implementation
//In order to prevent "java.sql.SQLRecoverableException: Closed Connection: next" error
//We are using CachedRowSet
crs = new CachedRowSetImpl();
crs.populate(resultSet);
} catch (SQLException e) {
System.out.println("Problem occurred at executeQuery operation : " + e);
throw e;
} finally {
if (resultSet != null) {
//Close resultSet
resultSet.close();
}
if (stmt != null) {
//Close Statement
stmt.close();
}
//Close connection
dbDisconnect();
}
//Return CachedRowSet
return crs;
}
I try because I don't know how to solve my problem and i expect that this problem will be solve
Upvotes: 2
Views: 472
Reputation: 44952
com.sun.rowset.CachedRowSetImpl
is a JDBC implementation detail. By historic convention all the classes under com.sun
package are considered implementation detail. The distinction between JDK implementation detail and interface was enforced with the introduction of Java 9 module system.
In short you don't want to write your code depending on the JDK implementation details as they can change without warning.
See How to Use CachedRowSet in JDBC, section 3. Creating a CachedRowSet Object, which shows how to create the same object using RowSetProvider
and a CachedRowSet
interface:
RowSetFactory rsf = RowSetProvider.newFactory();
CachedRowSet crs = rsf.createCachedRowSet();
Upvotes: 2