Search code examples
javasql-serverjdbc

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


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.

enter image description here


Solution

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