Ejemplo n.º 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;
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 3
0
  public boolean update(Person c) throws Exception {
    PreparedStatement ps;

    try {
      ps = conn.getConn().prepareStatement(SQL_UPDATE);
      ps.setString(1, c.getNamePerson());
      ps.setString(2, c.getTelephonePerson());
      ps.setInt(3, c.getIdPerson());
      if (ps.executeUpdate() > 0) {
        return true;
      }
    } catch (SQLException e) {
      new exceptionConverter();
      throw exceptionConverter.getException("Problemas en la base de datos Personas", e);
    } finally {
      conn.closeConnection();
    }
    return false;
  }
Ejemplo n.º 4
0
  public List<Loan> getAll() {
    List<Loan> list = new ArrayList<Loan>();

    try {
      PreparedStatement ps;
      ResultSet res;

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

      Comic c = new Comic();
      Person p = new Person();

      while (res.next()) {

        Loan l = new Loan();
        l.setIdLoan(res.getInt("idLoan"));

        l.setComic(c);
        c.setNameComic(res.getString("nameComic"));

        l.setPerson(p);
        p.setNamePerson(res.getString("namePerson"));

        l.setDate(res.getString("date"));

        list.add(l);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      conn.closeConnection();
    }
    return list;
  }