查询所有学生记录,包含年级名称
@Override public LIst<Student>getAllStudent() throws Exception{ List<Student> list=new ArrayList<Student>(); String sql="SELECT * FROM Student,Grade WHERE Student.GradeId=Grade.GradeId AND GradeName=?" ResultSet rs = executeQuery(sql,gradeName); if(rs!=null){ while(rs.next()){ //获取学生值 Student student=new Student(); student.setGradeId(rs.getInt("gradeId")); student.setStudentName(rs.getString("StudentName")); student.setStudentNo(rs.getInt("studentNo")); //获取的就是当前学生的年级信息 Grade grade=new Grade(); grade.setGradeName(rs.getString("gradeName")); student.setGrade(grade); list.add(student); } } closeResource(); return list; }
查询S1年级下的学生记录
@Override public LIst<Users>getUsersbyAddress(Student address) throws Exception{ LIst<Users> list=new ArrayList<Users>(); //准备SQL String sql="select * from users where user_name like ?"; ResultSet rs = executeQuery(sql,"%"+address+"%"); if(rs!=null){ while(rs.next()){ //创建User对象保存每一条数据的值 Users users=new Users(); users.setUser_id(rs.getInt("user_id")); Users.setUser_name(rs.getString("user_name")); users.setUser_code(rs.getString("user_code")); Users.setUser_password(rs.getString("user_password")); } } //关闭资源 closeResource(); return list; }