Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

The JDBC driver warns that com.mysql.jdbc.Driver is deprecated

ErrorLoading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.

Short answer

The warning means something still names the Connector/J 5.1 class. From Connector/J 8.0 on, the driver class is com.mysql.cj.jdbc.Driver and the old name is deprecated. Change the name in your code or config, and depend on the com.mysql:mysql-connector-j artifact.

  • Applies to Connector/J 8.4, Java 21, Maven 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Search the whole project, including config and environment files, for the old class name. Every hit is a place that must change.

    grep -rn "com.mysql.jdbc.Driver" --include="*.java" --include="*.properties" --include="*.yml" --include="*.yaml" --include="*.xml" .
  2. 2Match what you see, then jump to its fix

    1. 1grep finds com.mysql.jdbc.Driver in a Class.forName call, a properties file or another setting that holds the driver class name.Code or config names the old driver classFix
    2. 2The build file lists a Connector/J 5.1 version, and the new class name cannot be found.The project still depends on the 5.1 driverFix

What does the error look like?

  • Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.

Cause 1 of 2

Code or config names the old driver class

1Check

The Connector/J documentation says the class that implements java.sql.Driver changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver, and that the old class name is deprecated.

grep -rn "driver" src/main/resources/

2Fix

Replace the name everywhere it appears.

// Java: the same change applies in any config file that holds the class name
Class.forName("com.mysql.cj.jdbc.Driver");

3Verify

Start the app and confirm the warning is gone from the log.

grep -c "This is deprecated" app.log

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 2

The project still depends on the 5.1 driver

1Check

The new class name exists only in Connector/J 8.0 and later. Print the dependency tree and read the version.

mvn dependency:tree -Dincludes=mysql

2Fix

Use the Connector/J coordinates the MySQL manual gives: group com.mysql, artifact mysql-connector-j. Set the version to a current release from the Connector/J download page, then use the new class name.

<dependency>
  <groupId>com.mysql</groupId>
  <artifactId>mysql-connector-j</artifactId>
  <version>${mysql.connector.version}</version>
</dependency>

3Verify

The dependency tree shows com.mysql:mysql-connector-j and the app connects.

mvn dependency:tree -Dincludes=com.mysql

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Keep one driver class name in one config place, not scattered over code.
  • Search for old driver names after every driver upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.