我只是试着运行下面的代码:
import com.sun.rowset.CachedRowSetImpl;
public class Test {
public static void main(String[] args) throws Exception{
CachedRowSetImpl crs = new CachedRowSetImpl();
}
}
当我运行它时,我得到:
错误:(1,15) java:包com.sun.rowset不可见(包com.sun.rowset是在模块java.sql.rowset中声明的,不会导出它)
我正在使用IntelliJ,并且我试图导入rs2xml.jar,但这仍然没有帮助。
发布于 2018-01-07 01:20:48
使用Java 9
你不能再访问这个类了。在理想的情况下,你不应该这样做。这是因为该类的包不会导出到模块javax.sql.rowset
中。在Java-9
中这样做的正确方法是:
import javax.sql.rowset.*;
public class Test {
public static void main(String[] args) throws Exception {
CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
}
}
要理解这一点,我们可以转到模块描述(module-info.java
)并找到导出包的列表:
exports javax.sql.rowset;
exports javax.sql.rowset.serial;
exports javax.sql.rowset.spi;
发布于 2018-08-17 02:27:03
这应该与Java 10一起使用
而不是
CachedRowSet crs = new CachedRowSetImpl();
使用
CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
发布于 2021-04-05 02:39:31
除了这里的答案之外,重要的是要注意,即使在Java8中,也不应该使用com.sun.rowset.CachedRowSetImpl
。
正如在Are there any good CachedRowSet implementations other than the Sun one?中所解释的,RowSetProvider
是获得CachedRowSet
的标准方法。
来自sun
的包是internal and subject to change。除非由JDK开发人员使用,否则不应该使用它们。
https://stackoverflow.com/questions/48129475
复制相似问题