解决思路:
1、如果提示下面错误信息,确认JDBC驱动版本和MySQL版本是否对应;
严重: Servlet.service() for servlet [jsp] in context with path [/jspex] threw exception [javax.servlet.ServletException: java.sql.SQLException: Unknown system variable 'query_cache_size'] with root cause
java.sql.SQLException: Unknown system variable 'query_cache_size'
MySQL5及其低版本:
Class.forName("com.mysql.jdbc.Driver");
MySQL6及其高版本:
Class.forName("com.mysql.cj.jdbc.Driver");
JDBC驱动所有版本下载链接:
http://central.maven.org/maven2/mysql/mysql-connector-java/
2、确认建立连接语句是否正确;
如果提示下面错误信息,说明缺少serverTimezone参数。
Stacktrace:] with root cause
com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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.
需要添加:
serverTimezone=UTC
UTC代表的是全球标准时间,如果在中国,要使用是北京时区也就是东八区,领先UTC八个小时。
//北京时间东八区
serverTimezone=GMT%2B8
//或者使用上海时间
serverTimezone=Asia/Shanghai
原因:
比如在java代码里面插入的时间为:2018-06-24 17:29:56
但是在数据库里面显示的时间却为:2018-06-24 09:29:56
本文介绍了当JDBC连接MySQL数据库失败时的解决步骤,包括检查JDBC驱动版本与MySQL版本的匹配性,以及调整连接字符串中serverTimezone参数,确保正确处理时区差异,以避免时间显示不一致的问题。
1万+

被折叠的 条评论
为什么被折叠?



