コード例 #1
0
ファイル: DAO.java プロジェクト: vinids86/StarDapioWebService
  public List<Pedido> getPedido(long idRestaurant, long mesa, long idCliente) {
    String sql =
        "select * from pedido "
            + "where id_restaurant = "
            + idRestaurant
            + " and mesa = "
            + mesa
            + " and id_cliente = "
            + idCliente;
    try {
      List<Pedido> pedidos = new ArrayList<Pedido>();
      PreparedStatement stmt = this.connection.prepareStatement(sql);
      ResultSet rs = stmt.executeQuery();

      while (rs.next()) {
        Pedido pedido = new Pedido();
        pedido.setIdCliente(rs.getString("id_cliente"));
        pedido.setIdRestaurant(rs.getLong("id_restaurant"));
        pedido.addItem(getItem(rs.getLong("item")));
        pedido.setMesa(rs.getLong("mesa"));
        pedido.setColuna(rs.getInt("coluna"));
        pedidos.add(pedido);
      }
      rs.close();
      stmt.close();
      return pedidos;
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #2
0
ファイル: DAO.java プロジェクト: vinids86/StarDapioWebService
  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);
    }
  }