package shuji;
import java.sql.*;
public class Date {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn=null;
Statement stmt=null;
String DB_URL="jdbc:mysql://localhost:3306/student";
String user="root";
String pass="******";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, user, pass);
stmt = conn.createStatement();
String sql = "SELECT * FROM student";
ResultSet rs = stmt.executeQuery(sql);//(4)
while (rs.next()) {
int id = rs.getInt("ID");
String name = rs.getString("Name");
String sex = rs.getString("Sex");
String address = rs.getString("Address");
System.out.print("ID: " + id);
System.out.print(", 姓名: " + name);
System.out.print(", 性别: " + sex);
System.out.print(", 地址: " + address);
System.out.print("\n");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
System.out.print(e);
}
}
}
在链接最后面添加&useSSL=false
参考:https://blog.csdn.net/qq_44096670/article/details/129566356
String DB_URL="jdbc:mysql://localhost:3306/student?useSSL=false";