问题
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