Java “正在加载类 com.mysql.jdbc.Driver ... 已弃用”消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52344453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:24:25  来源:igfitidea点击:

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

javamysqljdbc

提问by maria

Hello can you explain it to me, why is it instead of using com.mysql.jdbc.DriverI got an error

你好,你能给我解释一下吗,为什么是它而不是使用com.mysql.jdbc.Driver我有一个错误

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.

加载类com.mysql.jdbc.Driver。这已被弃用。新的驱动程序类是com.mysql.cj.jdbc.Driver。驱动程序通过 SPI 自动注册,通常不需要手动加载驱动程序类。

Your help is much appreciated

非常感谢您的帮助

采纳答案by Gord Thompson

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:

主要是告诉你驱动类的名字改成了com.mysql.cj.jdbc.Driver. 因此,请改用:

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.forNameanyway, because JDBC is now able to load the correct driver itself (provided that the driver .jar is available on the class path).

它还让您知道,从 Java 6 (JDBC 4.0) 开始,通常不需要使用Class.forName任何方式手动加载驱动程序类,因为 JDBC 现在能够加载正确的驱动程序本身(前提是驱动程序 .jar 在类路径)。

回答by Denys Dvornyi

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

我在 Spring Boot 应用程序中遇到了同样的问题。
我在“application.properties”文件中添加了新参数:

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

And this solved my problem.

这解决了我的问题。