使用JDBC連線MySql時報錯:You must configure either the server or JDBC driver (via the serverTimezone cconfig
阿新 • • 發佈:2018-12-20
在使用JDBC連線MySql時報錯: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.
具體報錯如下:
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.
解決方法:
在配置檔案中的 連線字串後面加上?serverTimezone=UTC
UTC是統一標準世界時間
完整的連線字串示例:jdbc:mysql://localhost:3306/hello?serverTimezone=UTC
順便一提,如果輸入中文存在亂碼,可以如下設定:
jdbc:mysql://127.0.0.1:3306/hello?useUnicode=true&characterEncoding=UTF-8
當然,為了穩妥,你也可以都寫上 如下:
jdbc:mysql://127.0.0.1:3306/hello?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
搞定。