(Mysql8.x连接JDBC时报错:java.sql.SQLException: The server time zone value
‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone.)
描述:
以前用的Mysql 5.x版本的jar包不能使用在Mysql 8.x版本下,会出现拒绝连接的情况。那么如何更换jar包呢?过程中需要注意的问题有哪些?
1.首先需要下载Mysql 8.x版本的jar,其实在安装Mysql 8.x时就带了对应版本的Java
jar包,在图中位置找到可找到jar包
2.复制粘贴到项目下,在IDEA软件下需要点击项目右键–>Add As
Library完成jar包的导入
3.注册驱动需要添加cj
Class.forName("com.mysql.cj.jdbc.Driver");
4.4. 出现报错问题:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
。
时区不对,解决方式:在getConnection的url参数中添加db3后面的代码
db3是笔者自己的数据表。
DriverManager.getConnection("jdbc:mysql://localhost:3306/db3?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&useSSL=false"
并且使用UTF-8可以解决中文乱码问题。