java访问数据库,报错提示:java.sql.SQLException: The server time zone value ‘???ú±ê×??±??‘ is unrecognized or

原博客文章:https://blog.csdn.net/weixin_40916641/article/details/80546040

错误提示1:

java.sql.SQLException
:服务器时区值’???ê×?? ?? ??” 无法识别或代表多个时区。如果要利用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值。在com.mysql.cj.jdbc.exceptions。 SQLError.createSQLException(SQLError.java:127)在com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)

原因:一般是JDBC驱动版本的问题

解决方法:按照提示把代码中
com.mysql.jdbc.Driver

改成
com.mysql.cj.jdbc.Driver

如:

public static final String DB_DRIVER = "com.mysql.jdbc.Driver";
public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
错误提示2

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并且为服务器证书验证提供信任库。

解决方法

数据库连接地址
public static final String DB_URL = "jdbc:mysql://localhost:3306"/数据库名称;

在数据库名称后面添加
?useUnicode=true&characterEncoding=utf-8&useSSL=false

即:public static final String DB_URL = "jdbc:mysql://localhost:3306"/数据库名称?useUnicode=true&characterEncoding=utf-8&useSSL=false;

如:

    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://localhost:3306/java-work01";
    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://localhost:3306/java-work01?useUnicode=true&characterEncoding=utf-8&useSSL=false";
错误提示3

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

原因:数据库和系统时区差异造成的

解决方法
数据库连接地址
public static final String DB_URL = "jdbc:mysql://localhost:3306"/数据库名称?useUnicode=true&characterEncoding=utf-8&useSSL=false;

在数据库连接地址末端加上
&serverTimezone = GMT

即:public static final String DB_URL = "jdbc:mysql://localhost:3306"/数据库名称?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT;

如:

    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://localhost:3306/java-work01?useUnicode=true&characterEncoding=utf-8&useSSL=false";
    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://localhost:3306/java-work01?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT";
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值