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用不用都無所謂,但不用會有無證書警告

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