Example #1
0
  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);
    }
  }
Example #2
0
  public void adicionaPedido(Pedido pedido) {
    String sql =
        "insert into pedido "
            + "(id_cliente, id_restaurant, item, mesa, coluna)"
            + "values (?, ?, ?, ?, ?)";
    try {
      PreparedStatement stmt = connection.prepareStatement(sql);

      List<Item> itens = pedido.getItens();
      for (Item i : itens) {
        stmt.setString(1, pedido.getIdCliente());
        stmt.setLong(2, pedido.getIdRestaurant());
        stmt.setInt(3, i.getIdItem());
        stmt.setLong(4, pedido.getMesa());
        stmt.setInt(5, pedido.getColuna());
        stmt.execute();
      }
      // Por execute dentro do laço

      stmt.close();
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
Example #3
0
  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);
    }
  }
Example #4
0
  public void inserirItem(Item item) {
    String sql =
        "insert into item"
            + "(name, price, description, urlImage, id_restaurant, id_type)"
            + "values (?, ?, ?, ?, ?, ?)";
    try {
      PreparedStatement stmt = connection.prepareStatement(sql);

      stmt.setString(1, item.getName());
      stmt.setDouble(2, item.getPrice());
      stmt.setString(3, item.getDescription());
      stmt.setString(4, item.getUrlImage());
      stmt.setInt(5, item.getIdRestaurante());
      stmt.setInt(6, item.getIdType());

      stmt.execute();
      stmt.close();
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }