public boolean insertSkillInfo(String personnelID, Skill sk) {
    boolean check = true;
    PreparedStatement ps;
    if (dbc.connect()) {
      try {
        String sqlQuery = "INSERT INTO " + SKILL_INFO + " VALUES(?,?,?,?,?)";
        ps = dbc.getConnection().prepareStatement(sqlQuery);
        ps.setString(1, personnelID);
        ps.setShort(2, sk.getNameID());
        ps.setShort(3, sk.getClassificationID());
        ps.setNString(4, sk.getNote());
        if (sk.getEffectiveDate() == null) {
          ps.setNull(5, java.sql.Types.DATE);
        } else {
          ps.setDate(5, sk.getEffectiveDate());
        }

        if (ps.executeUpdate() < 1) {
          check = false;
        }
      } catch (SQLException ex) {
        Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return check;
  }
Пример #2
0
  @Override
  public Collection<TeacherDTO> getTeachers() {
    ArrayList<TeacherDTO> teacherDTOs = new ArrayList<>();
    Query query = entityManager.createNamedQuery("Teacher.findAll");
    List<Teacher> teachers = query.getResultList();
    query = entityManager.createNamedQuery("Skill.findAll");
    List<Skill> skills = query.getResultList();
    ArrayList<SkillDTO> skillsDTO = new ArrayList<>();

    for (Skill s : skills) {
      skillsDTO.add(new SkillDTO(s.getId().intValue(), s.getSkillName()));
    }

    for (Teacher t : teachers) {
      teacherDTOs.add(new TeacherDTO(t.getFirstName(), t.getLastName(), t.getCpr(), skillsDTO));
    }
    return teacherDTOs;
  }
  public ArrayList<Skill> getSkill(String personnelID) {
    ArrayList<Skill> skList = new ArrayList<>();
    PreparedStatement ps;
    ResultSet rs;
    if (dbc.connect()) {
      try {
        String sqlQuery =
            "select "
                + SKILL_COLUMN
                + " from "
                + SKILL_INFO
                + " where MaNV = '"
                + personnelID
                + "'";
        ps = dbc.getConnection().prepareStatement(sqlQuery);
        rs = ps.executeQuery();

        while (rs.next()) {
          Skill sk = new Skill();

          sk.setNameID(rs.getShort(1));
          sk.setClassificationID(rs.getShort(2));
          sk.setEffectiveDate(rs.getDate(3));
          sk.setNote(rs.getString(4));
          sk.setID_IDENTITY(rs.getShort(5));

          skList.add(sk);
        }
      } catch (SQLException ex) {
        Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return skList;
  }