java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exce

咱們在使用java 開發時,忽然發現mysql 驅動加載失敗,沒法連接,並且報以下錯誤,如圖1所示java

圖1,錯誤顯示mysql

錯誤描述:將錯誤進行了複製,以下所示:
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=utf-8'.
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:131)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:231)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
    at tree.DataProcess.<clinit>(DataProcess.java:18)
    at tree.Travelsal.getFileInfo(Travelsal.java:18)
    at tree.Main.main(Main.java:13)
Caused by: com.mysql.cj.exceptions.UnableToConnectException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=utf-8'.
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103)
    ... 6 more
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=utf-8'.
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
  ......
緣由:mysql的驅動發生了更新,以前的連接方式須要改變sql

以前:jdbc:mysql://localhost:3306/tree?useUnicode=true&amp;characterEncoding=utf-8app

如今:jdbc:mysql://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMTspa

將以前的連接改爲如今的連接後,就不會出現這個問題。.net

驅動名也記得改哦-》Class.forName("com.mysql.cj.jdbc.Driver");code

如上圖所示,便不會有問題了。若是您的問題尚未解決的話能夠參考以下連接,這個連接裏有比我更詳細的解決辦法。orm

參考連接:https://blog.csdn.net/wd2014610/article/details/80861261server

相關文章
相關標籤/搜索