@Override public List<Student> findByFourCondition( String stuNumber, String stuName, int stuMajId, String stuGradeNow) throws Exception { List<Student> studentList = new ArrayList<Student>(); Student student = null; String sql = "select * from student where stuNumber like ? and stuName like ? and majorId=? and gradeNow=?"; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, "%" + stuNumber + "%"); pstmt.setString(2, "%" + stuName + "%"); pstmt.setInt(3, stuMajId); pstmt.setString(4, stuGradeNow); rs = pstmt.executeQuery(); while (rs.next()) { student = new Student(); student.setId(rs.getInt(1)); student.setStuNumber(rs.getString(2)); student.setStuPassword(rs.getString(3)); student.setStuName(rs.getString(4)); student.setStuSex(rs.getString(5)); student.setStuIdentification(rs.getString(6)); student.setStuIsGat(rs.getString(7)); student.setStuPhone(rs.getString(8)); student.setDepartmentId(rs.getInt(9)); student.setMajorId(rs.getInt(10)); student.setGradeNow(rs.getString(11)); student.setNationMark(rs.getInt(12)); student.setBithday(rs.getString(13)); student.setAddress(rs.getString(14)); student.setPolitics(rs.getString(15)); studentList.add(student); } } catch (Exception e) { e.printStackTrace(); } finally { DatabaseConnection.closeResultSet(rs); DatabaseConnection.closePreparedStatement(pstmt); DatabaseConnection.closeConnection(conn); } return studentList; }
@Override public Student findByStuNumber(String stuNumber) throws Exception { Student student = null; String sql = "select * from student where stuNumber=?"; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, stuNumber); rs = pstmt.executeQuery(); while (rs.next()) { student = new Student(); student.setId(rs.getInt(1)); student.setStuNumber(rs.getString(2)); student.setStuPassword(rs.getString(3)); student.setStuName(rs.getString(4)); student.setStuSex(rs.getString(5)); student.setStuIdentification(rs.getString(6)); student.setStuIsGat(rs.getString(7)); student.setStuPhone(rs.getString(8)); student.setDepartmentId(rs.getInt(9)); student.setMajorId(rs.getInt(10)); student.setGradeNow(rs.getString(11)); student.setNationMark(rs.getInt(12)); student.setBithday(rs.getString(13)); student.setAddress(rs.getString(14)); student.setPolitics(rs.getString(15)); } } catch (Exception e) { e.printStackTrace(); } finally { DatabaseConnection.closeResultSet(rs); DatabaseConnection.closePreparedStatement(pstmt); DatabaseConnection.closeConnection(conn); } return student; }