Java连接Mysql由于版本更新报错

参考博客https://www.cnblogs.com/yongdongma/p/9911393.html

 

错误描述:错误进行了复制,如下所示:
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的驱动发生了更新,之前的链接方式需要改变

之前:jdbc:MysqL://localhost:3306/tree?useUnicode=true&amp;characterEncoding=utf-8

现在:jdbc:MysqL://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT

将之前的链接改成现在的链接后,就不会出现这个问题。

驱动名也记得改哦-》Class.forName("com.MysqL.cj.jdbc.Driver");

如上图所示,便不会有问题了。如果您的问题还没有解决的话可以参考如下链接,这个链接里有比我更详细的解决办法。

 

相关文章

连接数据库的方式:第一种方式:ODBC:开放数据库连接是微软...
JDBCRequest 使用VariableNamesmysql:数据库连接池对象var...
 1.JDBCDBC(JavaDataBaseConnectivity):Java数据库连接技术...
1.需要jar包的支持:java.sqljavax.sqlmysql-conneter-java....
1.简介Activiti是一个业务流程管理(BPM)框架,它是覆盖了业务...
1.JDBC体系系统一组规范:接口JDBC接口(API)包括两个层次:...