MySQL JDBC: com.mysql.cj.jdbc.Driver vs com.mysql.jdbc.Driver
For Java developers who connect to MySQL through JDBC and need the driver class name, or the fix for an error about it.
On this page
Your configuration needs the name of the MySQL driver class, or your log shows a deprecation warning, a ClassNotFoundException or "No suitable driver". Use com.mysql.cj.jdbc.Driver, the driver class of MySQL Connector/J 8.0 and every later release. com.mysql.jdbc.Driver is the Connector/J 5.1 name: it still loads, and prints a warning.
| Setting | Value |
|---|---|
| Driver class, Connector/J 8.0 and later | com.mysql.cj.jdbc.Driver |
| Legacy class, Connector/J 5.1 | com.mysql.jdbc.Driver |
| URL prefix | jdbc:mysql:// |
| Default port | 3306 |
Which Connector/J versions use which class
Connector/J 5.1 has only com.mysql.jdbc.Driver. Connector/J 8.0 moved the driver to com.mysql.cj.jdbc.Driver, and MySQL's upgrade guide says "The old class name has been deprecated"[1]. Connector/J 26.10.0, the current release of October 2026, still ships both classes. The javap tool shows how the two relate:
javap -cp mysql-connector-j-26.10.0.jar com.mysql.jdbc.Driver
Compiled from "Driver.java"
public class com.mysql.jdbc.Driver extends com.mysql.cj.jdbc.Driver {
public com.mysql.jdbc.Driver() throws java.sql.SQLException;
static {};
}
The old class extends the new one, so code that names the old class still gets the current driver.
The Maven artifact also got a new name, and the driver class inside it stayed the same. mysql-connector-j vs mysql-connector-java explains which coordinates to use.
What "Loading class com.mysql.jdbc.Driver. This is deprecated" means
The warning means that your code or configuration still names com.mysql.jdbc.Driver. The connection still works. With Connector/J 26.10.0 on Java 25, Class.forName("com.mysql.jdbc.Driver") printed this line on stderr:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
The old class prints the line when it loads, once per JVM: we loaded it twice and saw the line once. The connection to MySQL 9.1.0 then succeeded, and DriverManager.getDrivers() listed one driver, com.mysql.cj.jdbc.Driver version 26.10.
To remove the warning, replace the old name wherever you set it, such as spring.datasource.driver-class-name or hibernate.connection.driver_class. In plain JDBC code, delete the Class.forName line.
Do you need Class.forName for the MySQL JDBC driver?
You need Class.forName only when the Connector/J jar sits inside a web application. When DriverManager initializes, it loads every driver that the service-provider mechanism (the SPI of the warning) finds on the classpath[2]. Connector/J declares its class for that mechanism: the file META-INF/services/java.sql.Driver in the 26.10.0 jar holds one line, com.mysql.cj.jdbc.Driver.
With the jar on the classpath, this program connects without naming a driver class:
import java.sql.Connection;
import java.sql.DriverManager;
public class Connect {
public static void main(String[] args) throws Exception {
try (Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/shopdb", "root", "password")) {
System.out.println(conn.getCatalog() + " is up");
}
}
}
Against a server with a shopdb database, the program printed:
shopdb is up
On Tomcat, the DriverManager scan runs once, at startup. That scan sees only the jars that all web applications share, such as those in $CATALINA_HOME/lib[3]. A driver in your application's WEB-INF/lib is not among them, so it never registers by itself. Move the jar to $CATALINA_HOME/lib, or keep Class.forName("com.mysql.cj.jdbc.Driver") in the application.
How to fix ClassNotFoundException: com.mysql.cj.jdbc.Driver
ClassNotFoundException: com.mysql.cj.jdbc.Driver means that the Connector/J jar is missing from the classpath of the running JVM. The class name is right. Without the jar, Class.forName("com.mysql.cj.jdbc.Driver") failed with:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
The jar goes missing in one of three ways:
- The jar is on the classpath of the build, but not on the classpath of the command that starts the application.
- The Maven dependency has test or provided scope. Maven leaves both scopes off the runtime classpath, so compiling and testing succeed, and the application fails at run time[4].
- A server such as Tomcat is meant to supply the jar from its lib folder, and the jar is not there.
To see the scope, print the dependency tree of the module that opens the connection:
mvn dependency:tree -Dincludes=com.mysql:mysql-connector-j
In a module that declares the driver with test scope, the entry ends in :test:
[INFO] \- com.mysql:mysql-connector-j:jar:26.10.0:test
Change the scope from test or provided to compile or runtime. If the tree shows no entry, that module does not declare the dependency at all.
How to fix No suitable driver found for jdbc:mysql
"No suitable driver" means that no registered driver accepted the URL. DriverManager offers the URL to each driver that your code's class loader can see[2]. We changed one thing at a time against a MySQL 9.1.0 server, with Connector/J 26.10.0 on Java 25:
| What we changed | Result |
|---|---|
| jar not on the classpath, no Class.forName | No suitable driver, SQLState 08001 |
| jdbc:mysql//… (colon missing) | No suitable driver, SQLState 08001 |
| jdbc:mysq://… (typo) | No suitable driver, SQLState 08001 |
| a space before jdbc:mysql:// | No suitable driver, SQLState 08001 |
| jdbc:MySQL://… (upper case) | connected |
| jar loaded only by a separate class loader | No suitable driver, SQLState 08001 |
A missing jar also causes "No suitable driver" when no code loads the class by name. Check two things, in this order:
- The URL starts with jdbc:mysql:// exactly. The MySQL JDBC URL guide covers the rest of the URL.
- DriverManager.getDrivers(), called from the code that fails, lists com.mysql.cj.jdbc.Driver. When we loaded the jar in a separate class loader, getDrivers() listed nothing to the calling code. An empty list means that the jar is missing, or sits in a class loader that your code can't see, as in the Tomcat case.
Once the driver accepts the URL, the next errors come from connecting and signing in, such as Public Key Retrieval is not allowed.
How DbSchema loads the MySQL driver class
DbSchema names the driver class for you. For MySQL, the driver settings of DbSchema list com.mysql.cj.jdbc.Driver first, followed by older class names. DbSchema downloads the Connector/J jar from dbschema.com the first time you connect, so you set neither a jar nor a class[5].
To use your own jar, for example on a computer without internet access, open Database → Manage → JDBC Drivers Manager and press Upload Driver Jar(s).
To watch the steps, see the video MySQL JDBC Driver: Download, Configure and See Your Database as an ER Diagram.
Download DbSchema and connect to MySQL in the free Community Edition: DbSchema loads Connector/J for you, and reverse-engineers the schema into a diagram that you can explore.
Sources
Connect to MySQL without naming a driver class
DbSchema downloads MySQL Connector/J the first time you connect, picks the driver class from its own driver definition, and reverse-engineers the schema into diagrams in the free Community Edition.