参考博客:https://www.cnblogs.com/yongdongma/p/9911393.html 错误描述:将错误进行了复制,如下所示:java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exce...
参考博客: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&characterEncoding=utf-8
现在:jdbc:mysql://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
将之前的链接改成现在的链接后,就不会出现这个问题。
驱动名也记得改哦-》Class.forName("com.mysql.cj.jdbc.Driver");
如上图所示,便不会有问题了。如果您的问题还没有解决的话可以参考如下链接,这个链接里有比我更详细的解决办法。
本文标题为:Java连接Mysql由于版本更新报错
基础教程推荐
- SpringCloud gateway+zookeeper实现网关路由的详细搭建 2023-04-12
- springboot实现指定mybatis中mapper文件扫描路径 2022-12-07
- Java将本地项目部署到Linux服务器的实践 2022-12-03
- Spring基于注解的缓存声明深入探究 2023-04-07
- JAVA时间存储类Period和Duration使用详解 2023-06-02
- SpringSecurity自定义登录界面 2023-05-14
- 详解JNA中的回调方法 2022-11-25
- Java迭代器与Collection接口超详细讲解 2023-03-11
- Java 中不全部使用 Static 方法的理由 2023-04-06
- Java设计模式之解释器模式 2023-06-06