问题描述:
使用JdbcTemplate连接数据库时出现java.sql.SQLException异常:
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 specific time zone value if you want to utilize time zone support.
原因分析:
jdbc驱动新特性:连接数据库的"url"需指定UTC时区
原代码:
![]()
解决方案:
在"url"属性值后添加:
?useCharactorEncoding=utf-8&useSSL=false&serverTimezone=UTC
修改后代码:
jdbc:mysql://localhost:3306/spring_db?useCharactorEncoding=utf-8&useSSL=false&serverTimezone=UTC
本文详细解析了在使用JdbcTemplate连接数据库时遇到的关于时区设置的SQLException,并提供了代码示例。关键在于理解新JDBC驱动对URL时区的要求,如何在连接字符串中添加'UTC'来确保正确的时间处理。
1025

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



