public boolean insertHealthStatus(String personnelID, HealthStatus hs) { boolean check = true; PreparedStatement ps; if (dbc.connect()) { try { String sqlQuery = "INSERT INTO " + HEALTH_STATUS + " VALUES(?,?,?,?,?,?,?,?,?)"; ps = dbc.getConnection().prepareStatement(sqlQuery); ps.setString(1, personnelID); if (hs.getHealDate() == null) { ps.setNull(2, java.sql.Types.DATE); } else { ps.setDate(2, hs.getHealDate()); } ps.setNString(3, hs.getHospital()); ps.setShort(4, hs.getHeight()); ps.setShort(5, hs.getWeight()); ps.setString(6, hs.getSight()); ps.setShort(7, hs.getBloodID()); ps.setShort(8, hs.getHealthStatusID()); ps.setNString(9, hs.getNote()); if (ps.executeUpdate() < 1) { check = false; } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return check; }
public ArrayList<HealthStatus> getHealthStatus(String personnelID) { ArrayList<HealthStatus> hsList = new ArrayList<>(); PreparedStatement ps; ResultSet rs; if (dbc.connect()) { try { String sqlQuery = "select " + HEALTH_COLUMN + " from " + HEALTH_STATUS + " where MaNV = '" + personnelID + "'"; ps = dbc.getConnection().prepareStatement(sqlQuery); rs = ps.executeQuery(); while (rs.next()) { HealthStatus hs = new HealthStatus(); hs.setHealDate(rs.getDate(1)); hs.setHospital(rs.getString(2)); hs.setHeight(rs.getShort(3)); hs.setWeight(rs.getShort(4)); hs.setSight(rs.getString(5)); hs.setBloodID(rs.getShort(6)); hs.setHealthStatusID(rs.getShort(7)); hs.setNote(rs.getString(8)); hs.setID_IDENTITY(rs.getShort(9)); hsList.add(hs); } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return hsList; }