所抛异常:
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'.
解决办法:
- 修改mysql-connector包为8.0+版本;
maven dependency:
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
-
修改驱动driverClassName为:com.mysql.cj.jdbc.Driver;
-
url地址需要变动
eg:
原:jdbc:mysql://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8
现在:
jdbc:mysql://localhost:3306/tree?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
注意:在实际使用中,曾经遇到过这样的问题:
就是在查取数据时间的过程中,代码查取到的时间跟数据库插入的时间不一致,相差8个小时
这是因为数据库的时区不对,所以要将serverTimezone = GMT
修改成
serverTimezone = Asia/Shanghai