コード例 #1
0
 @Override
 public boolean update(Student student) {
   boolean result = true;
   try {
     updateStatement.setString(1, student.getUser());
     updateStatement.setString(2, student.getPassword());
     updateStatement.setString(3, student.getNames());
     updateStatement.setString(4, student.getSurnames());
     updateStatement.setString(5, student.getEmail());
     updateStatement.executeUpdate();
     result = true;
   } catch (SQLException e) {
     result = false;
     logger.error(e);
   }
   return result;
 }
コード例 #2
0
 @Override
 public boolean delete(Student student) {
   boolean result = true;
   try {
     deleteStatement.setInt(1, student.getId());
     deleteStatement.executeUpdate();
     result = true;
   } catch (SQLException e) {
     result = false;
     logger.error(e);
   }
   return result;
 }
コード例 #3
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;
  }
コード例 #4
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;
 }