コード例 #1
0
  public List<Person> getAll() throws Exception {
    List<Person> list = new ArrayList<Person>();

    try {
      PreparedStatement ps;
      ResultSet res;

      ps = conn.getConn().prepareStatement(SQL_GET_ALL);
      res = ps.executeQuery();

      while (res.next()) {

        Person c = new Person();
        c.setIdPerson(res.getInt("idPerson"));
        c.setNamePerson(res.getString("namePerson"));
        c.setTelephonePerson(res.getString("telephonePerson"));

        list.add(c);
      }

    } catch (SQLException e) {
      new exceptionConverter();
      throw exceptionConverter.getException("Problemas en la base de datos Personas", e);
    } finally {
      conn.closeConnection();
    }
    return list;
  }
コード例 #2
0
  public Person get(int key) throws Exception {
    Person p = new Person();

    try {

      PreparedStatement ps;
      ResultSet res;

      ps = conn.getConn().prepareStatement(SQL_GET);
      ps.setInt(1, key);

      res = ps.executeQuery();
      while (res.next()) {
        p.setIdPerson(res.getInt("idPerson"));
        p.setNamePerson(res.getString("namePerson"));
        p.setTelephonePerson(res.getString("telephonePerson"));
      }

    } catch (SQLException e) {
      new exceptionConverter();
      throw exceptionConverter.getException("Problemas en la base de datos Personas", e);
    } finally {
      conn.closeConnection();
    }
    return p;
  }