Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA ERROR : package com.sun.rowset is not visible : com.sun.rowset is declared in module java.sql.rowset, which does not export it

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.

like image 760
user2962142 Avatar asked Jan 06 '18 16:01

user2962142


2 Answers

With Java 9 you can not access this class anymore. 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 will be:

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;
like image 59
Andremoniy Avatar answered Nov 06 '22 00:11

Andremoniy


This should be used with Java 10

Instead of

CachedRowSet crs = new CachedRowSetImpl();

use

CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
like image 2
fahim reza Avatar answered Nov 06 '22 00:11

fahim reza