10

I'm simply try to run this code:

import com.sun.rowset.CachedRowSetImpl;

public class Test {
    public static void main(String[] args) throws Exception{
        CachedRowSetImpl crs = new CachedRowSetImpl();
    }
}

When I run it I get:

Error:(1, 15) java: package com.sun.rowset is not visible (package com.sun.rowset is declared in module java.sql.rowset, which does not export it)

I'm using IntelliJ and I tried to import rs2xml.jar, and that still doesnt help.

Makoto
  • 104,088
  • 27
  • 192
  • 230
user2962142
  • 1,916
  • 7
  • 28
  • 42

3 Answers3

18

As of Java 9, you can not access this class directly. And in the ideal way you shouldn't do that. That is because this class's package is not exported in the module javax.sql.rowset.

The proper way to do that in Java 9+ is the use of RowSetProvider to access a RowSetFactory to produce an instance of an implementation of CachedRowSet

import javax.sql.rowset.*; 

public class Test {
    public static void main(String[] args) throws Exception {

        CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
    }
}

To understand that we can go to the module description (module-info.java) and find a list of exported packages:

exports javax.sql.rowset;
exports javax.sql.rowset.serial;
exports javax.sql.rowset.spi;
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
3

This should be used with Java 10

Instead of

CachedRowSet crs = new CachedRowSetImpl();

use

CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
Anj Raju
  • 606
  • 7
  • 7
1

In addition to the answers here, it is important to note that you should never use com.sun.rowset.CachedRowSetImpl, even in Java 8.

As explained at Are there any good CachedRowSet implementations other than the Sun one? , the RowSetProvider is the standard way to obtain a CachedRowSet.

Packages from sun are internal and subject to change. They should never be used except by JDK developers.

A248
  • 690
  • 7
  • 17