JDBC连接MySql时报错:Exception in thread "main" java.sql.SQLException: The server time zone value '???ú±ê×

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 即可。
配好之后打印连接如图所示就说明连接成功:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/hnu_zzt/article/details/88424997