java连接Mysql数据库失败

问题

  1. 无法连接到数据库:可能是因为导入的mysql-connector-java-x.x.xx.jar版本过低,无数据库版本不匹配。解决办法:下载最新的包导入,同时更改jdbc.driverClass = com.mysql.dbc.Driver为jdbc.driverClass = com.mysql.cj.jdbc.Driver
  2. mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one。解决办法:从错误即可知道是时区的错误,因此只要将时区设置为你当前系统时区即可,因此使用root用户登录mysql,按照如下图所示操作即可.我电脑的系统为北京时区,因此在系统中设置后,再连接数据库运行,一切OK!
  3. 或者:private static final String URL = "jdbc:mysql://localhost:3306/db_lottery?useSSL=false&serverTimezone=UTC";
  4. db_lottery为数据库文件,useSSL=false表示不使用SSL证书,serverTimezone=UTC

                                                      

猜你喜欢

转载自blog.csdn.net/qq_38635681/article/details/84783655