JDBC连接数据库是报错:Could not create connection to database server。或如题示报错。如图所示:
在这里错误的参数配置如下:
driverClassName:com.mysql.jdbc.Driver
url:jdbc:mysql://localhost:3306/test
username:root
password:12345678
MySQL8.0版本需要更换驱动为“com.mysql.cj.jdbc.Driver”,之前的“com.mysql.jdbc.Driver”已经不能在MySQL 8.0版本使用了。
然后将url改成: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false 即可。
配好之后打印连接如图所示就说明连接成功: