原博客文章: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";