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; }
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; }