今天在连接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";
原文:https://www.cnblogs.com/AmosWong/p/9388046.html