“加载类 com.mysql.jdbc.Driver ... 已弃用";信息 [英] "Loading class com.mysql.jdbc.Driver ... is deprecated" message

查看:45
本文介绍了“加载类 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天全站免登陆