Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Loading class com.mysql.jdbc.Driver ... is deprecated" message

Tags:

java

mysql

jdbc

Hello can you explain it to me, why is it instead of using com.mysql.jdbc.Driver 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.

Your help is much appreciated

like image 601
maria Avatar asked Sep 15 '18 11:09

maria


People also ask

Which JDBC type driver class has been deprecated in Java 8?

cj. jdbc. Driver. The old class name has been deprecated."

What is the meaning of class forName com mysql JDBC driver?

The Class class is located in the java. lang package, so it is distributed with java, and imported automatically into every class. What the forName() method does, is just return the Class object for the paramater that was loaded by the class loader. The newInstance() method then returns a new instance of the class.


2 Answers

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).

like image 180
Gord Thompson Avatar answered Oct 21 '22 20:10

Gord Thompson


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.

like image 5
Denys Dvornyi Avatar answered Oct 21 '22 21:10

Denys Dvornyi