java.sql.SQLException: The server time zone value '???ú±ê×??±??'的报错解决方案

问题描述:

利用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用不用都无所谓,但不用会有无证书警告

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章