问题描述:
利用JDBC连接数据时,会报错误具: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 specifc time zone value if you want to utilize time zone support.具体错误如图所示:
解决办法:
ps:database的粗体表示你要连接的数据库,记得改成自己的数据库。
String url = "jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
即可。
解释:
1.'???ú±ê×??±??'说明乱码,编码方式不能显示中文,改编码方式characterEncoding=utf8
2.设置Unicode=true方便java编码
3.mysql返回的时间有问题,一般总是早8小时,改serverTimezone=GMT%2B8
4.useSSL用不用都无所谓,但不用会有无证书警告
解决JDBC连接MySQL乱码及时间偏移问题
本文详细介绍了在使用JDBC连接MySQL数据库时遇到的乱码和时间偏移问题,并提供了解决方案。通过设置正确的字符编码和时区配置,可以避免这些问题,确保数据正确读取。
1026

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



