“不推荐使用加载类com.mysql.jdbc.Driver ...”信息 [英] "Loading class com.mysql.jdbc.Driver ... is deprecated" message

查看:83
本文介绍了“不推荐使用加载类com.mysql.jdbc.Driver ...”信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,你能解释一下吗,为什么不用 com.mysql.jdbc.Driver 我收到了错误

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


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

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.

非常感谢您的帮助

推荐答案

这不是错误;它是由

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

致电。尽管有消息,您的代码仍会继续运行。

call. Your code continues to run despite the message.

主要是告诉你驱动程序类的名称已更改为 com.mysql.cj.jdbc.Driver 。所以,改为使用:

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

它也让你知道,自Java 6(JDBC 4.0)以来,通常不需要使用手动加载驱动程序类 Class.forName 无论如何,因为JDBC现在能够加载正确的驱动程序(假设驱动程序.jar在类路径上可用)。

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

这篇关于“不推荐使用加载类com.mysql.jdbc.Driver ...”信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆