关于JDBC连接MySQL数据库发生的异常

1.浅谈mysql-connector-java-5.1.46.jar和mysql-connector-java-8.0.15.jar的区别

因为版本不同,其加载数据库驱动程序的方式也会有所不同

  • mysql-connector-java-5.1.46.jar
com.mysql.jdbc.Driver

JDBC连接数据库的具体参数如下:

String driver = "com.mysql.jdbc.Driver";
String url = "数据库连接地址";
String user = "用户名";
String password = "密码";

  • mysql-connector-java-8.0.15.jar
com.mysql.cj.jdbc.Driver

JDBC连接数据库的具体参数如下:

String driver = "com.mysql.cj.jdbc.Driver";
String url = "数据库连接地址";
String user = "用户名";
String password = "密码";

2.有些时候,当我们与url指定的数据库建立连接时会出现小小的错误,如下:

 2.1.

Exception:

Sat Jun 02 11:40:45 CST 2018 WARN:建议不建立服务器身份验证的SSL连接。根据MySQL 5.5.45 +,5.6.26 +和5.7.6+的要求,如果未设置显式选项,则必须默认建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为'false'。您需要通过设置useSSL = false显式禁用SSL,或者设置useSSL = true并且为服务器证书验证提供信任库。

 Example:

String url = "jdbc:mysql://localhost:3306/account";

Resolution:

?useUnicode=true&characterEncoding=utf-8&useSSL=false

Realization:

String url = "jdbc:mysql://localhost:3306/account?useUnicode=true&characterEncoding=utf-8&useSSL=false";

2.2.

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 specifc time zone value if you want to utilize time zone support.


 java.sql.SQLException中:服务器时区值'??? EE×??±??' 。无法识别或代表多个时区如果要利用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值。

 Example:

String url = "jdbc:mysql://localhost:3306/account";

Resolution:

?serverTimezone=UTC

Realization:

String url = "jdbc:mysql://localhost:3306/school?serverTimezone=UTC";

参考如下:

(12条消息) java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more_我是一只青蛙的博客-CSDN博客https://blog.csdn.net/weixin_40916641/article/details/80546040

(12条消息) 解决JDBC连接mysql时server time zone问题及com.mysql.jdbc.Driver is deprecated_有时候我也会的博客-CSDN博客https://blog.csdn.net/weixin_43849277/article/details/107518043


com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 serverTimezone设定 - 一起学编程 - 博客园 (cnblogs.com)https://www.cnblogs.com/bestjdg/p/12239036.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来得晚一些也行

观众老爷,请赏~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值