系统:Win10
Java:1.8.0_333
IDEA:2020.3.4
MySQL:8.0.30
Gitee:https://gitee.com/lijinjiang01/JavaWeb
首先创建项目,导入驱动 jar 包
Class.forName("com.mysql.cj.jdbc.Driver"); // 旧版的是 com.mysql.jdbc.Driver
Connection conn = DriverManager.getConnection(url, username, password);
String sql = "SELECT * FROM tb01";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();