“Package not accessible” error trying to import SQL Server JDBC package in project

早过忘川 提交于 2021-02-17 05:12:13

问题


I'm trying to use the SQL Server JDBC package in my Java project. I'm getting a The package com.microsoft.sqlserver.jdbc is not accessible error in my import statement. I've already added the MSSQL JDBC driver to the appropriate classpath (see attached image). I have another project set up exactly the same way that works just fine. The driver used is the same and the import statements match. Here are my import statements:

package Main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.*;

None of the other import statements throw an error. I am using this driver: mssql-jdbc-7.4.1.jre12.jar. I am also using JDK 13 for both projects.


回答1:


I deleted module-info.java and this resolved the error.




回答2:


Put a string requires java.sql; in the module-info.java file.



来源:https://stackoverflow.com/questions/59312443/package-not-accessible-error-trying-to-import-sql-server-jdbc-package-in-proje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!