今天学习了用查找函数返回查找完成的数组
public List<classes> Select() {
String sql = "select * from classes";
Connection conn = DBUtil_Classes.getConnection();
PreparedStatement st = null;
List<classes> list = new ArrayList<>();
classes classes = null;
ResultSet rs = null;
try {
st = conn.prepareStatement(sql);
st.executeQuery(sql);
rs = st.executeQuery(sql);
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
int number = rs.getInt("number");
String teacher = rs.getString("teacher");
int isnumber = rs.getInt("isnumber");
classes = new classes(id, name, number, teacher, isnumber);
list.add(classes);
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally {
DBUtil_Classes.close(conn);
DBUtil_Classes.close(st);
DBUtil_Classes.close(rs);
return list;
}
}