import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class Select {
public static void main(String[] args) throws Exception {
String driverName = "com.mysql.cj.jdbc.Driver";
String userName = "root";
String userPwd = "";
String dbName = "students";
String url = "jdbc:mysql://localhost:3306/" + dbName + "?useSSL=false&serverTimezone=UTC";
Class.forName(driverName);
Connection conn = DriverManager.getConnection(url, userName, userPwd);
if (!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
Statement stmt = conn.createStatement();
String sql = "select * from stu where cj>=0 and cj<=100";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
System.out.println("记录号 学号 姓名 成绩");
while (rs.next()) {
int a = rs.getRow();
int b = rs.getInt("xh");
String c = rs.getString("name");
int d = rs.getInt("cj");
System.out.println(a + " | " + b + " | " + c + " | " + d);
}
pstmt.close();
stmt.close();
conn.close();
}
}