问题
使用mysql的jdbc驱动最新版(6.0+)时,会遇到数据库和系统时区差异引起的问题,如下:
Caused by: java.sql.SQLException: The server time zone value 'XXXXXXXXX' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) touse a more specifc time zone value if you want to utilize time zone support.
解决
- 降低版本(不推荐)
- 在jdbc连接的url后面加上serverTimezone=Asia/Shanghai即可,如下:
jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&characterEncoding=utf8 如果实在xml文件中注意&要用&实体替代,如下 jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&characterEncoding=utf8