標籤:res with 注意 tag 寫法 mysq att 修改 url
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&serverTimezone=UTC </property>
即可。在xml的設定檔中 ;要用 & 代替。
Exception in thread “main” java.sql.SQLException: The server time zone value ‘?й???????’ is unrecognized or represents more than one time zone.