出现这个问题的原因是,mysql 8.0版本后,需要在url后面增加一些参数(必不可少)
原
String DB_URL = "jdbc:mysql://localhost:3306/testdb";
新
String DB_URL = "jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
pom中引入mysql依赖项
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>