jdbc版本怎么看_JDBC驱动`com.mysql.jdbc.Driver'. This is deprecated

JDBC --导入MySQL驱动,然后试着操作数据库数据

package 

然后就悲剧了,看了视频中的代码一遍又一遍,,,,一句。。。。。

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.

Exception in thread "main" java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value if you want to utilize time zone support.

了解到和 和 MySQL的版本有关系:

MySQL5用的驱动url是com.mysql.jdbc.Driver,MySQL6以后用的是com.mysql.cj.jdbc.Driver

然后赶紧看了下自己使用的MySQL 版本是:8.0.17 MySQL

使用的驱动:mysql-connector-java-8.0.22 ,而学习资料中用的5.1.7版本,那问题就找到了

c8eafd7824c6355ce60238f9066e0ab6.png

更改 加载驱动为:

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

但是仍然有问题

Exception in thread "main" java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value if you want to utilize time zone support.

必须配置服务器或JDBC驱动程序(通过“serverTimezone”配置属性)以使用更特定的时区值。

设置属性:

可以选择东8区的Hongkong、Asia/Shanghai或者Asia/Hongkong作为参数,修改后url为

        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true",
                "root", "root123");

还有其他的参数设置:

参考MySql 官方资料

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-using-ssl.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值