首页 > 数据库技术 > 详细

JDBC学习笔记

时间:2018-07-29 22:53:05      阅读:194      评论:0      收藏:0      [点我收藏+]

今天在连接JDBC时,出现了错误

最开始的URL是这样写的

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/alibaba

报错为:

1.Establishing SSL connection without server‘s identity verification is not recommended

原因:mysql版本过高创建连接 

解决办法:在mysql连接上加上&useSSL=true

2.Loading class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver‘.

解决方法:由于mysql 的版本过高 需要将原来的加载驱动改为:class.forName("com.mysql.cj.jdbc.Driver")

3.报错为:The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more than one time zone

出现这个的原因是因为 mysql返回的时间总是有问题,比实际时间要早8小时。

 在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8

最后URL变为:jdbc:mysql://localhost:3306/alibaba?serverTimezone=GMT&useSSL=false

当然网上也有更完善的版本:String url = "jdbc:mysql://localhost:3306/test_10?useUnicode=true&characterEncoding=utf-8&useSSL=false&&serverTimezone=GMT";

JDBC学习笔记

原文:https://www.cnblogs.com/AmosWong/p/9388046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!