"Loading class com.mysql.jdbc.Driver ... is deprecated" message
Asked Answered
L

3

20

I got an error

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.

Could someone explain why?

Lanky answered 15/9, 2018 at 11:52 Comment(1)
This is not an error. It is a warning.Manganese
D
43

It isn't an error; it is a warning (or advisory) message resulting from a

Class.forName("com.mysql.jdbc.Driver")

call. Your code continues to run despite the message.

It is mainly telling you that the name of the driver class has changed to com.mysql.cj.jdbc.Driver. So, instead use:

Class.forName("com.mysql.cj.jdbc.Driver")

It is also letting you know that since Java 6 (JDBC 4.0) it is usually not necessary to manually load the driver class using Class.forName anyway, because JDBC is now able to load the correct driver itself (provided that the driver .jar is available on the class path).

Dickinson answered 15/9, 2018 at 12:43 Comment(2)
Could you please say why was com.mysql.jdbc.driver deprecated in the first place? What is wrong with that?Eviscerate
@JohnBrookfields, a quick google search mentions that merely the name has changed, nothing else. This is common (like Spring changing the name of properties-placeholders from time to time). Official documentation at 4.4.1.3 Changes in the Connector/J API from dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.htmlFusiform
B
8

I had the same problem in my Spring Boot application.
I added new parameter to my 'application.properties' file:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

And this solved my problem.

Bhakti answered 20/11, 2018 at 13:53 Comment(0)
M
0

I know that this is solved. However, my issue was that the code I was working on did not allow my to change the class from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. I spent hours trying to figure this out.

In the application.properties file the connection string, username and password were already defined. I had copied 8.0.26 mysql jar into the Tomcat/lib folder and none of that helped.

The answer pointed out to me by the team lead was to add my connection info into the catalina.properties file. Which would of course be counterintuitive to having multiple projects that used the same naming convention but different endpoints.

The workaround for me:

catalina.properties
    CONNECTION_STRING="xxxxxx"
    CONNECTION_USER="xxxxxx"
    CONNECTION_PASS="xxxxxxX"
    SERVER_ADDRESS="xxxxxx"
Mccarthy answered 1/2 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.