public List<Item> getItemType(int idRestaurante, int idType) { String sql = "select * from item " + "where id_restaurant = " + idRestaurante + " and id_type = " + idType; try { List<Item> itens = new ArrayList<Item>(); PreparedStatement stmt = this.connection.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { Item item = new Item(); item.setIdItem(rs.getInt("id")); item.setName(rs.getString("name")); item.setPrice(rs.getDouble("price")); item.setDescription(rs.getString("description")); item.setUrlImage(rs.getString("urlImage")); item.setIdRestaurante(rs.getInt("id_restaurant")); item.setIdType(rs.getInt("id_type")); itens.add(item); } rs.close(); stmt.close(); return itens; } catch (SQLException e) { throw new RuntimeException(e); } }
private Item getItem(long id) { String sql = "select * from item " + "where id = " + id; try { Item item = new Item(); PreparedStatement stmt = this.connection.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { item.setIdItem(rs.getInt("id")); item.setName(rs.getString("name")); item.setPrice(rs.getDouble("price")); item.setDescription(rs.getString("description")); item.setUrlImage(rs.getString("urlImage")); item.setIdRestaurante(rs.getInt("id_restaurant")); item.setIdType(rs.getInt("id_type")); } rs.close(); stmt.close(); return item; } catch (SQLException e) { throw new RuntimeException(e); } }