CommunicationsException:Communications link failure的錯誤

出現如題錯誤,內容大概這樣(多的我也不截取了,又不是爲了湊字數,網上不少人把全部異常粘上,人都得下拉半天)

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,033 milliseconds ago.  The last packet sent successfully to the server was 2,024 milliseconds ago.
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

網上一搜肯定是一堆說巴拉巴拉如下類似內容:

wait_timeout默認是8小時,一個空閒的連接超過8小時,MySQL將自動斷開連接,連接池卻覺得這個連接可用,然後就相當於用失效連接了,然後就出錯…
然後讓你在mysql的安裝文件夾找my.ini文件(網上安裝mysql教程都會讓用戶創建一個my.ini文件,因爲mysql8壓縮包沒有這個文件需要手動添加),用notepad++打開,增加time_out時間,interactive_timeout時間啦,加成31536000,還有一年的等等

當然我不是是說上面的方法有錯,因爲有些人確實通過那種方法解決了。

我今天說的是同樣的報錯,適用我的程序的解決方案。如果你的情況用了上面的解決不了,可以試下我的。

方法:

打開自己創建的數據庫配置文件,我的是jdbc.properties文件。我最開始的內容下

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8&useSSL=true
jdbc.username=root
jdbc.password=*******

大家基本內容都相同,不同的是mybatis是各自的庫名。?後表示數據庫設置,多個用&連接。

一種解決是將SSL=true選項刪除掉,但是會報

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 。。。。等等警告

另一種是將useSSL賦值爲false,這樣就不會警告了。

希望我的內容能幫到你,謝謝

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章