1. 程式人生 > >Exception in thread “main” java.sql.SQLException: The server time zone value ‘?й???????’ is unrecognized or represents more than one time zone.

Exception in thread “main” java.sql.SQLException: The server time zone value ‘?й???????’ is unrecognized or represents more than one time zone.

odin 異常 參數 執行 cif must ant -h base

Exception in thread “main” 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.

解決方法

根據異常提示可知需要添加對應的時區,修改url即可

String url = String.format(“jdbc:mysql://%s:%d/%s?characterEncoding=%s&serverTimezone=UTC”, host, port, database, encoding);

在XML中

提示系統時區出現錯誤,可以在mysql中執行命令:

set global time_zone=‘+8:00‘
或者在數據庫驅動的url後加上serverTimezone=UTC參數

寫代碼的時候要註意,如果該參數是‘?’後的第一個,即

<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?serverTimezone=UTC </property>

是沒有問題的,但如果不是第一個,即

<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&serverTimezone=UTC </property>

這種寫法是會報錯的,會提示The reference to entity “serverTimezone” must end with the ‘;’ delimiter.
運行後控制臺也會出現
對實體 “serverTimezone” 的引用必須以 ‘;’ 分隔符結尾。
的錯誤提示。
將代碼改為

<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&amp;serverTimezone=UTC </property>

即可。在xml的配置文件中 ;要用 &amp; 代替。

Exception in thread “main” java.sql.SQLException: The server time zone value ‘?й???????’ is unrecognized or represents more than one time zone.