Esempio n. 1
0
  public void updateAgent(Agent agent) {
    try {
      conn = JDBC_Conn.getConnection();
      String sql =
          "update agents set phone_number=?, email=?, first_nm=?, last_nm=?, dob=?, zip=?, gender=? where agent_id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, agent.getPhone_number());
      stmt.setString(2, agent.getEmail());
      stmt.setString(3, agent.getFirst_nm());
      stmt.setString(4, agent.getLast_nm());
      stmt.setDate(5, new java.sql.Date(agent.getDob().getTime()));
      stmt.setString(6, agent.getZip());
      stmt.setString(7, agent.getGender());
      stmt.setString(8, agent.getAgent_id());
      stmt.executeUpdate();

      sql = "update position set position = ? where agent_id=?";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, agent.getPosition());
      stmt.setString(2, agent.getAgent_id());
      stmt.executeUpdate();

    } catch (Exception e) {
      e.printStackTrace();
      throw new DAOException();
    } finally {
      JDBC_Conn.releaseConnection(conn, stmt, rs);
    }
  }
Esempio n. 2
0
  public void addAgent(Agent agent) {

    try {
      conn = JDBC_Conn.getConnection();
      String sql = "insert into agents values(?,?,?,?,?,?,?,?)";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, agent.getAgent_id());
      stmt.setString(2, agent.getPhone_number());
      stmt.setString(3, agent.getEmail());
      stmt.setString(4, agent.getFirst_nm());
      stmt.setString(5, agent.getLast_nm());
      stmt.setDate(6, new java.sql.Date(agent.getDob().getTime()));
      stmt.setString(7, agent.getZip());
      stmt.setString(8, agent.getGender());
      stmt.executeUpdate();

      sql = "insert into position values(?,?)";
      stmt = conn.prepareStatement(sql);
      stmt.setString(1, agent.getAgent_id());
      stmt.setString(2, agent.getPosition());
      stmt.executeUpdate();

    } catch (Exception e) {
      e.printStackTrace();
      throw new DAOException();
    } finally {
      JDBC_Conn.releaseConnection(conn, stmt, rs);
    }
  }