コード例 #1
0
  public boolean updateOfficeList(Office o) {
    boolean check = true;
    PreparedStatement ps;
    if (dbc.connect()) {
      try {
        String sqlQuery = "INSERT INTO " + getOFFICE_CB() + " VALUES(?,?)";
        ps = dbc.getConnection().prepareStatement(sqlQuery);

        ps.setNString(1, o.getOfficeName());
        ps.setString(2, o.getOfficeNum());

        if (ps.executeUpdate() < 1) {
          check = false;
        }
      } catch (SQLException ex) {
        Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return check;
  }
コード例 #2
0
  public ArrayList<Office> getOffice() {
    ArrayList<Office> off = new ArrayList<>();
    PreparedStatement ps;
    ResultSet rs;
    if (dbc.connect()) {
      try {
        String sqlQuery = "select * from " + getOFFICE_CB();
        ps = dbc.getConnection().prepareStatement(sqlQuery);
        rs = ps.executeQuery();

        while (rs.next()) {
          Office o = new Office();
          o.setOfficeID(rs.getShort(1));
          o.setOfficeName(rs.getNString(2));
          o.setOfficeNum(rs.getString(3));

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