基于MySQL8.0+进行JDBC连接的”坑“

  1. 驱动加载语句更改
    JDBC driver 由“com.mysql.jdbc.Driver”改为“com.mysql.cj.jdbc.Driver”
  2. url中加上“userSSL=false”
  3. url中加上“serverTimezone=GMT%2B8”(GMT%2B8代表东八区)
    或者直接修改数据库的默认时区:
进入到MySQL中:
---
show variables like '%time_zone%';
set global time_zone='+8:00';

JDBC_Test

Class.forName("com.mysql.cj.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/tmall_ssm?useUnicode=true&characterEncoding=utf8&userSSL=false&serverTimezone=GMT%2B8",
                        "root", "root");
Statement s = c.createStatement();
String sql = ......
s.execute(sql);```

你可能感兴趣的:(Java,SE)