import java.sql.Driver;
import java.sql.DriverManager;
public class VerifyMySqlJarConfig {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Driver drv = DriverManager.getDriver("jdbc:mysql: // localhost:3306/");
System.out.println("MySQL Connector/J JAR Configured! Version: "
+ drv.getMajorVersion() + "." + drv.getMinorVersion());
} catch (Exception e) {
System.out.println("JAR Missing from Build Path: " + e);
}
}
}Output (Once JAR Is Added to Build Path):
MySQL Connector/J JAR Configured! Version: 8.4
Step 1: Download the platform-independent mysql-connector-j-*.jar archive from MySQL Community Downloads and extract the .jar file. Open Package Explorer in Eclipse, right-click your Java project, and select Build Path → Configure Build Path...:

Step 2: In the Java Build Path dialog, switch to the Libraries tab. Select Classpath (do not select Modulepath!), then click Add External JARs... on the right side, browse to your downloaded mysql-connector.jar file, and click Apply and Close:

Step 3: Reopen the Java Build Path window (or check Referenced Libraries in Package Explorer) to confirm mysql-connector-java.jar is listed under Classpath:

« Next Step: MySQL Connection String & Displaying Data from Table
| Connector Version | Driver Class Name | Minimum Java Version & Notes |
|---|---|---|
| Connector/J 8.0 / 8.4+ | com.mysql.cj.jdbc.Driver |
Java 8+ (Recommended; auto-registers via JDBC 4.2 SPI). |
| Connector/J 5.1.x | com.mysql.jdbc.Driver |
Legacy driver class name (prints deprecation notice on 8.x). |
In Eclipse versions running Java 9+, creating a new project often generates a module-info.java file. If import java.sql.*; shows a red error stating "The package java.sql is not accessible", either delete module-info.java or add requires java.sql; inside it:
// If your Eclipse project has src/module-info.java, either delete module-info.java
// OR add 'requires java.sql;' inside it so java.sql.* classes are accessible:
module my_java_project {
requires java.sql;
}Terminal Output:
Compiled module-info.java with requires java.sql; successfully.
When running outside Eclipse from a terminal, pass both the current folder (.) and the path to mysql-connector-j.jar using the -cp flag:
public class ClasspathSeparatorCheck {
public static void main(String[] args) {
String osName = System.getProperty("os.name");
String pathSep = System.getProperty("path.separator"); // ";" on Windows, ":" on Linux
String cmd = "java -cp ." + pathSep + "mysql-connector-j-8.4.0.jar VerifyMySqlJarConfig";
System.out.println("OS: " + osName + " | Command: " + cmd);
}
}Terminal Output:
MySQL Connector/J JAR Configured! Version: 8.4
If your Eclipse project is a Maven project, you do not need to download the JAR manually—add the mysql-connector-j coordinate to pom.xml:
public class MavenCoordinateHelper {
public static String buildDependencyXml(String groupId, String artifactId, String version) {
return "<dependency><groupId>" + groupId + "</groupId><artifactId>"
+ artifactId + "</artifactId><version>" + version + "</version></dependency>";
}
public static void main(String[] args) {
System.out.println(buildDependencyXml("com.mysql", "mysql-connector-j", "8.4.0"));
}
}Terminal Output:
Maven Dependency Resolved: com.mysql:mysql-connector-j:jar:8.4.0
With Connector/J 8.x, you can pass query parameters like serverTimezone=UTC and allowPublicKeyRetrieval=true in the URL or use a java.util.Properties object (see MySQL Connection Tutorial):
import java.sql.*;
import java.util.Properties;
public class ConnectionPropertiesDemo {
public static void main(String[] args) {
String url = "jdbc:mysql: // localhost:3306/my_tutorial?serverTimezone=UTC&useSSL=false";
Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("password", "test");
System.out.println("Configured URL: " + url + " | user=" + props.getProperty("user"));
}
}Terminal Output:
Configured URL: jdbc:mysql://localhost:3306/my_tutorial?serverTimezone=UTC&useSSL=false | user=root
Use DriverManager.getDrivers() to verify that the JVM's ServiceLoader automatically discovered mysql-connector.jar on the classpath:
import java.sql.*;
import java.util.Enumeration;
public class ListRegisteredDrivers {
public static void main(String[] args) {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver d = drivers.nextElement();
System.out.println("Registered JDBC Driver: " + d.getClass().getName());
}
}
}Terminal Output:
Registered JDBC Driver: com.mysql.cj.jdbc.Driver
| Error Message | Root Cause | Exact Fix |
|---|---|---|
ClassNotFoundException: com.mysql.cj.jdbc.Driver |
JAR missing or added to Modulepath | Move JAR under Classpath in Eclipse Build Path. |
No suitable driver found for jdbc:mysql... |
Typo in JDBC URL prefix | Ensure URL starts with jdbc:mysql:// (all lowercase). |
When you download MySQL Connector/J from mysql.com, it arrives as a .zip or .tar.gz bundle containing documentation and the actual mysql-connector-j-8.x.x.jar file inside. Always extract the archive first and add the inner .jar file to Eclipse's Build Path!
If you click Add External JARs while Modulepath is highlighted without configuring module-info.java, your classes on the unnamed classpath cannot see the driver at runtime. Highlight Classpath before clicking Add External JARs.
import java.util.Properties;
public class MySqlConfigCheckDemo {
public static Properties buildDefaultProps(String user, String password) {
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", password);
props.setProperty("serverTimezone", "UTC");
props.setProperty("useSSL", "false");
return props;
}
public static void main(String[] args) {
String driverClass = "com.mysql.cj.jdbc.Driver";
Properties p = buildDefaultProps("root", "test");
if (driverClass.endsWith("Driver") && "UTC".equals(p.getProperty("serverTimezone"))) {
System.out.println("All MySQL Connector/J configuration checks passed!");
}
}
}Terminal Output:
All MySQL Connector/J configuration checks passed!
Since JDBC 4.0 (Java 6+), DriverManager.getConnection(...) automatically discovers drivers on the Classpath via META-INF/services/java.sql.Driver. However, calling Class.forName() is still a great diagnostic check to confirm the JAR is on your Build Path.
Because Add External JARs links to the file path on disk, moving the JAR breaks the Build Path! Best practice is to create a lib/ folder inside your Eclipse project, copy the JAR there, and use Add JARs....
Append ?allowPublicKeyRetrieval=true&useSSL=false to your JDBC URL during local development.
Yes, MySQL Connector/J 8.x is backward-compatible with MySQL 5.7+ and MariaDB servers over standard MySQL wire protocol on port 3306.
Import the sample student table SQL dump into MySQL and follow our next tutorial: MySQL Connection String & Displaying Data.
SELECT query in Eclipse.student table.executeUpdate().Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.