public boolean insertExperience(String personnelID, Experience exp) { boolean check = true; PreparedStatement ps; if (dbc.connect()) { try { String sqlQuery = "INSERT INTO " + EXPERIENCE_INFO + " VALUES(?,?,?,?,?,?,?,?,?,?,?)"; ps = dbc.getConnection().prepareStatement(sqlQuery); ps.setString(1, personnelID); ps.setNString(2, exp.getCompName()); ps.setNString(3, exp.getPos()); ps.setNString(4, exp.getJob()); if (exp.getStartDate() == null) { ps.setNull(5, java.sql.Types.DATE); } else { ps.setDate(5, exp.getStartDate()); } if (exp.getEndDate() == null) { ps.setNull(6, java.sql.Types.DATE); } else { ps.setDate(6, exp.getEndDate()); } ps.setNString(7, exp.getReason()); ps.setNString(8, exp.getReferName()); ps.setString(9, exp.getReferPhone()); ps.setString(10, exp.getReferEmail()); ps.setNString(11, exp.getReferPos()); if (ps.executeUpdate() < 1) { check = false; } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return check; }
public ArrayList<Experience> getExperience(String personnelID) { ArrayList<Experience> exList = new ArrayList<>(); PreparedStatement ps; ResultSet rs; if (dbc.connect()) { try { String sqlQuery = "select " + EXPERIENCE_COLUMN + " from " + EXPERIENCE_INFO + " where MaNV = '" + personnelID + "'"; ps = dbc.getConnection().prepareStatement(sqlQuery); rs = ps.executeQuery(); while (rs.next()) { Experience ex = new Experience(); ex.setCompName(rs.getString(1)); ex.setPos(rs.getString(2)); ex.setJob(rs.getString(3)); ex.setStartDate(rs.getDate(4)); ex.setEndDate(rs.getDate(5)); ex.setReferName(rs.getString(6)); ex.setReferPhone(rs.getString(7)); ex.setReferEmail(rs.getString(8)); ex.setReferPos(rs.getString(9)); ex.setID_IDENTITY(rs.getShort(10)); exList.add(ex); } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return exList; }