The JDBC driver warns that com.mysql.jdbc.Driver is deprecated
Loading 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.
Fix it fast
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" .2Match what you see, then jump to its fix
- 1
grep 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
The 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
- 1
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.logConfirmed by dev.mysql.com
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=mysql2Fix
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.mysqlConfirmed by dev.mysql.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Back end
Spring Boot cannot load the MySQL JDBC driver class
Cannot load driver class: com.mysql.jdbc.Driver
Spring Boot checks that the driver class you name can be loaded before it builds the connection pool.
3 causes, each with a fixBack end
JDBC executeQuery() on an INSERT, UPDATE or DELETE throws SQLException
java.sql.SQLException thrown by Statement.executeUpdate() when the SQL is a SELECT
executeQuery() is only for statements that produce one ResultSet.
3 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
The AWS SDK for Java cannot find credentials, and AwsCredentials.properties does nothing
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain
AwsCredentials.properties on the classpath is an old convention: the default provider chain of the AWS SDK for Java does not read it.
4 causes, each with a fixBack end
CodeIgniter 4: try/catch does not catch a failed insert in the model
DatabaseException
CodeIgniter throws a DatabaseException on a failed query only when DBDebug is true, and inside a transaction it does not throw unless you ask.
3 causes, each with a fixBack end
CodeIgniter 4 where() builds a different condition than you meant
A SQL syntax error that appears only when a value contains a quote character
The query builder joins every where() with AND and every orWhere() with OR, with no brackets.
3 causes, each with a fix