예제 #1
0
  public boolean addLoan(Comic c, Person p, String d) {
    Loan l = new Loan();
    l.setComic(c);
    l.setPerson(p);
    l.setDate(d);
    boolean rta = loandao.add(l);

    return rta;
  }
예제 #2
0
  public boolean add(Loan c) {
    try {
      PreparedStatement ps;
      ps = conn.getConn().prepareStatement(SQL_INSERT);

      ps.setInt(1, c.getPerson().getIdPerson());
      ps.setInt(2, c.getComic().getIdComic());
      ps.setString(3, c.getDate());

      if (ps.executeUpdate() > 0) {
        return true;
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      conn.closeConnection();
    }
    return false;
  }
예제 #3
0
  public Loan get(Object key) {
    Loan l = new Loan();

    try {

      PreparedStatement ps;
      ResultSet res;

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

      res = ps.executeQuery();
      while (res.next()) {
        l.setIdLoan(res.getInt("idLoan"));
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      conn.closeConnection();
    }
    return l;
  }
예제 #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;
  }