The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the serve

来源:https://www.cnblogs.com/chromer/archive/2018/09/27/java_1.html
-Advertisement-
Play Games

異常錯誤:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC dri ...


異常錯誤: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.

 1 Thu Sep 27 00:18:47 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 2 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.
 3     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
 4     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
 5     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
 6     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
 7     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
 8     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
 9     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
10     at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
11     at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
12     at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
13     at java.sql.DriverManager.getConnection(DriverManager.java:664)
14     at java.sql.DriverManager.getConnection(DriverManager.java:247)
15     at com.jdbc.chap02.sec03.Demo1.main(Demo1.java:33)
16 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.
17     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
18     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
19     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
20     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
21     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
22     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
23     at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128)
24     at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2236)
25     at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2260)
26     at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1314)
27     at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:963)
28     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:822)
29     ... 6 more
View Code

我用了8.0版本的MySQL連接驅動。現在按照最新官方提示支持將com.mysql.jdbc.Driver  改為  com.mysql.cj.jdbc.Driver

1 //驅動名稱
2 private static String jdbcName = "com.mysql.cj.jdbc.Driver";
3 //資料庫地址
4 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book";
5 //資料庫用戶名
6 private static String dbUser = "root";
7 //資料庫密碼
8 private static String dbPassword = "123456";

我們還需要在訪問資料庫的Url後面加上以下的語句即可:

1 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book?serverTimezone=GMT%2B8"

從錯誤上看應該是時區的錯誤,所以我們只需要設置完畢系統的時區即可。這裡的GMT%2B8代表東八區。

還有一種解決辦法就是設置整個資料庫的時區,可以執行下麵的語句來完成:

1 show variables like '%time_zone%'
2 set global time_zone='+8:00';
3 #執行結果:
4    Variable_name          Value
5 system_time_zone    
6       time_zone             SYSTEM

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 今年有人提出了2018年微服務將瘋狂至死,可見微服務的爭論從未停止過。在這我將自己對微服務的理解整理了一下,希望對大家有所幫助。 1.什麼是微服務 1)一組小的服務(大小沒有特別的標準,只要同一團隊的工程師理解服務的標識一致即可) 2)獨立的進程(java的tomcat,nodejs等) 3)輕量級 ...
  • 本文長度為2042字,建議閱讀6分鐘。所有「」包裹的文字,只對第一次出現進行高亮顯示。 閱讀目錄 「高可用」的作用? 如何來衡量「高可用」 做「高可用」的本質 結語 「高可用」的作用? 如何來衡量「高可用」 做「高可用」的本質 結語 「高可用」的作用? 如何來衡量「高可用」 做「高可用」的本質 結語 ...
  • 一.準備工作 準備3台機器,這樣才能完成分散式集群的實驗,當然能有更多機器更好: 192.168.3.64(e1) 192.168.3.62 (e2) 192.168.3.63(e3) 角色劃分: 3台機器全部安裝jdk1.8,因為elasticsearch是java開發的 3台全部安裝elasti ...
  • 教程:一:字典的創建 1:字典的介紹 >d = {key1:value1, key2:values2} (1)dictionary(字典) 是 Python 中最有用的數據類型。字典是無序的對象集合 (2)字典當中的元素是通過鍵來存取的,而不是通過偏移存取。 (3)字典是一種映射類型,它是一個無序的 ...
  • 美國時間 09 月 25 日,Oralce 正式發佈了 Java 11,這是據 Java 8 以後支持的首個長期版本。 為什麼說是長期版本,看下麵的官方發佈的支持路線圖表。 可以看出 Java 8 擴展支持到 2025 年,而 Java 11 擴展支持到 2026 年。 現在大部分都在用 Java ...
  • 程式員應該將核心關註點放在業務上,而不應該將時間過多的浪費在CRUD中,多數的ORM框架都把增加、修改與刪除做得非常不錯了,然後資料庫中查詢無疑是使用頻次最高、複雜度大、與性能密切相關的操作,我們希望得到一種使用方便,查詢靈活的ORM框架,MyBatis可以滿足這些要求,MyBatis是一個支持普通 ...
  • Java當中的泛型 01 這就存在一個問題,如果集合存儲元素時,而且存儲對象有很多,而且對象類型不相同,就很容易導致隱患。 在 中該文件 在編譯的時候不會出現錯誤是因為該存儲的是 的任何類型的對象,所以不會出現錯誤,編譯通過了。編譯後為 到運行。 如果要解決問題,可以把問題提前到編譯的時候去解決,讓 ...
  • 智能指針 shared_ptr 使用 上一篇 "智能指針是啥玩意" ,介紹了什麼是智能指針。 這一篇簡單說說如何使用智能指針。 一,智能指針分3類:今天只嘮嘮shared_ptr shared_ptr unique_ptr weak_ptr 二,下表是shared_ptr和unique_ptr都支持 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...