public ArrayList<Student> findAll() { ArrayList<Student> list = new ArrayList<Student>(); try { conn = JDBCUtils.getConnection(); stmt = conn.createStatement(); String sql = "select * from student"; System.out.println("单独查询SQL语句" + sql); rs = stmt.executeQuery(sql); while (rs.next()) { Student student = new Student(); student.setsNo(rs.getString("sNo")); student.setsName(rs.getString("sName")); student.setSex(rs.getString("Sex")); student.setclsNo(rs.getString("clsNo")); student.setsPwd(rs.getString("sPwd")); list.add(student); } return list; } catch (Exception ee) { ee.printStackTrace(); } finally { JDBCUtils.release(rs, stmt, conn); } return null; }重写
时间: 2024-02-14 10:18:54 浏览: 98
public List<Student> findAll() {
List<Student> list = new ArrayList<>();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = JDBCUtils.getConnection();
stmt = conn.createStatement();
String sql = "SELECT * FROM student";
System.out.println("查询SQL语句:" + sql);
rs = stmt.executeQuery(sql);
while (rs.next()) {
Student student = new Student();
student.setsNo(rs.getString("sNo"));
student.setsName(rs.getString("sName"));
student.setSex(rs.getString("sex"));
student.setClsNo(rs.getString("clsNo"));
student.setsPwd(rs.getString("sPwd"));
list.add(student);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtils.release(rs, stmt, conn);
}
return list;
}
阅读全文