Java Maven连接Mysql8.0时问题解决

MySQLNonTransientConnectionException: Could not create connection to database server.

不能连接到MySQL:

1.查看pom.mxl中MySQL驱动版本;如果版本不是8.0,添加依赖

     
        
            mysql
              mysql-connector-java
              8.0.11
        

2.修改驱动连接

   driver=com.mysql.cj.jdbc.Driver   (注意这里的"cj")

3.java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time 

   时区问题导致报错;

   有人说直接执行查询:set GLOBAL time_zone='+8:00';但这样只是暂时解bao决问题,下次打开工程还会报错!

   最终解决方式将数据库连接改为:url=jdbc:mysql://127.0.0.1:3306/MyDatabase+?serverTimezone=GMT%2B8

这里加上了时区  GMT%2B8   代表东八区

你可能感兴趣的:(jdbc)