/** * Add recruitment request to permanent store. * * @param toAdd request to be added * @return id of added request or -1 if unsuccessful */ public int addRecruitmentRequest(RecruitmentRequestBean toAdd) { String insertStatement = "insert into recruitmentrequests (requestdep, requestdate, jobtitle, contracttype, yearsofexperience, jobdescription, status) values (?,?,?,?,?,?,?);"; try { PreparedStatement statement = connection.prepareStatement(insertStatement, Statement.RETURN_GENERATED_KEYS); statement.setNString(1, toAdd.getRequestDepartment()); statement.setDate(2, new java.sql.Date(toAdd.getRequestDate().getTime())); statement.setNString(3, toAdd.getJobTitle()); statement.setNString(4, toAdd.getContractType()); statement.setInt(5, toAdd.getYearsOfExperience()); statement.setNString(6, toAdd.getJobDescription()); statement.setNString(7, "active"); statement.executeUpdate(); ResultSet rs = statement.getGeneratedKeys(); if (rs.first()) { return rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } return -1; }
public List<RecruitmentRequestBean> getRecruitmentRequests() { String query = "select id, requestdep, requestdate, jobtitle, contracttype, yearsofexperience, jobdescription, status from recruitmentrequests;"; try { Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query); List<RecruitmentRequestBean> result = new ArrayList<>(); boolean hasNext = resultSet.first(); while (hasNext) { int id = resultSet.getInt(1); RecruitmentRequestBean recruitmentRequest = new RecruitmentRequestBean(id); recruitmentRequest.setRequestDepartment(resultSet.getNString(2)); recruitmentRequest.setRequestDate(resultSet.getDate(3)); recruitmentRequest.setJobTitle(resultSet.getNString(4)); recruitmentRequest.setContractType(resultSet.getNString(5)); recruitmentRequest.setYearsOfExperience(resultSet.getInt(6)); recruitmentRequest.setJobDescription(resultSet.getNString(7)); recruitmentRequest.setStatus(resultSet.getNString(8)); result.add(recruitmentRequest); hasNext = resultSet.next(); } return result; } catch (SQLException e) { e.printStackTrace(); } return new ArrayList<>(); }