时间:2021-07-01 10:21:17 帮助过:4人阅读
DAO实现类
@Override public List<Student> selectStudents() throws Exception { List<Student> list=new ArrayList<Student>(); String sql="select * from Student,grade where Student.gradeid=grade.gradeid"; ResultSet exe = executeQuery(sql); if (exe!=null) { while (exe.next()) { Student stu=new Student(); grade grade=new grade(); stu.setStudentname(exe.getString("studentname")); stu.setSex(exe.getInt("sex")); grade.setGradename(exe.getString("gradename")); stu.setGrade(grade); list.add(stu); } } closs(); return list; }
entity
private int stduentNo; private String loginpwd; private String studentname; private int sex; private int gradeid; private String phone; private String address; private grade grade=new grade();
2.查询S1年级下的学生记
DAO实现类
@Override public grade selegrade(String gradename) throws Exception { grade grade=new com.myschool.entity.grade(); String sql="select * from Student,grade where Student.gradeid=grade.gradeid and gradename=?"; ResultSet rs = executeQuery(sql, gradename); if (rs!=null) { while (rs.next()) { grade.setGradename(rs.getString("gradename")); Student stu=new Student(); stu.setStudentname(rs.getString("studentname")); grade.getListStudents().add(stu); } } closs(); return grade; }
entity
private int gradeid; private String gradename; public List<Student> listStudents=new ArrayList<Student>();
课堂练习(mysql--java)
标签:login color entity add null HERE select from throws