Exemplo n.º 1
0
  public int insert(Pedido pedido) throws SQLException {

    Long idCliente = pedido.getIdCliente();
    String descricao = pedido.getDsPedido();

    try (Connection connection = new ConnectionFactory().getConnection()) {

      String sql =
          " insert into pedido (idPedido, idCliente, dsPedido) values (pedido_seq.nextval, ? ,?) ";
      PreparedStatement statement = connection.prepareStatement(sql);
      statement.setLong(1, idCliente);
      statement.setString(2, descricao);

      return statement.executeUpdate();
    } catch (SQLException e) {
      throw e;
    }
  }
Exemplo n.º 2
0
  public int update(Pedido pedido) throws SQLException {

    Long idPedido = pedido.getIdPedido();
    Long idCliente = pedido.getIdCliente();
    String descricao = pedido.getDsPedido();

    try (Connection connection = new ConnectionFactory().getConnection()) {

      String sql = " update pedido set idCliente = ?, dsPedido = ? where idPedido = ? ";
      PreparedStatement statement = connection.prepareStatement(sql);
      statement.setLong(1, idCliente);
      statement.setString(2, descricao);
      statement.setLong(3, idPedido);

      return statement.executeUpdate();
    } catch (SQLException e) {
      throw e;
    }
  }