jdbc报错The server time zone value ‘�й���׼ʱ��‘ is unrecognized

jdbc连接Mysql8.0

注册驱动:

Class.forName("com.mysql.jdbc.Driver");

报错:
Loading class ‘com.mysql.jdbc.Driver’. This is deprecated. The new
driver class is ‘com.mysql.cj.jdbc.Driver’

修改为

Class.forName("com.mysql.cj.jdbc.Driver");

================================================

获取数据库的连接对象:

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root","password");

报错:

The server time zone value ‘�й���׼ʱ��’ is unrecognized

需要指定时区serverTimezone,在设定时区时,若设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong。

例:

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db3?serverTimezone=Asia/Shanghai","root","password");

版权声明:本文为qq_45681074原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。