一、詳細報錯資訊
Caused by: 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.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2120)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2143)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 17 more
二、報錯原因
mysql 8.x 的 jdbc,增加了時區(serverTimezone)屬性,并且不允許為空,
三、解決
- 這種方法會存在一個問題,在向資料庫插入時間欄位時,時間會比當前時間早8小時,即當前系統時間減8小時,
jdbc.url=jdbc:mysql://localhost:3306/mydata?
serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
- 這種設定成東八區,可以同步資料插入時間與當前系統時間
jdbc.url=jdbc:mysql://localhost:3306/mydata?
serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
- 在1884年的國際本初子午線大會上格林尼治的子午線被正式定為經度的起點,東經180°即西經180°,約等同于國際換日線,國際換日線的兩邊,日期相差一日,
格林威治標準時間(GMT)
地區:英國 皇家格林尼治天文臺
時區:UTC/GMT 0 (零時區)
北京時差:現在格林威治時間比北京時間晚8小時
格林威治位于泰晤士河南岸,與北岸城鎮通隧道和公路,1423年格洛斯特公爵亨天雷圍建了格林尼治公園,在河畔山丘建了镃望塔,后又建造了格林威治皇家天文臺,
協調世界時(UTC)
UTC協調世界時即格林威治平太陽時間,是指格林威治所在地的標準時間,也是表示地球自轉速率的一種形式,UTC基于國際原子時間,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/203789.html
標籤:其他
上一篇:Oracle終極徹底卸載
