コード例 #1
0
  @Override
  public List<Student> findAll() {
    List<Student> students = new ArrayList<Student>();
    try {
      ResultSet result = findAllStatement.executeQuery();
      while (result.next()) {
        Student student = new Student();
        student.setId(result.getInt("id"));
        student.setUser(result.getString("user"));
        student.setPassword(result.getString("password"));
        student.setNames(result.getString("names"));
        student.setSurnames(result.getString("surname"));
        student.setEmail(result.getString("email"));

        students.add(student);
      }
    } catch (SQLException e) {
      students = null;
      logger.error(e.getLocalizedMessage());
    }
    return students;
  }
コード例 #2
0
 @Override
 public Student findById(int id) {
   Student student = null;
   try {
     findByIdStatement.setInt(1, id);
     ResultSet result = findByIdStatement.executeQuery();
     if (result.next()) {
       student = new Student();
       student.setId(result.getInt("id"));
       student.setUser(result.getString("user"));
       student.setPassword(result.getString("password"));
       student.setNames(result.getString("names"));
       student.setSurnames(result.getString("surname"));
       student.setEmail(result.getString("email"));
     } else {
       student = null;
     }
   } catch (SQLException e) {
     student = null;
     logger.error(e.getLocalizedMessage());
   }
   return student;
 }