コード例 #1
0
  @Override
  public boolean inserir(Item item) {

    String comandoSql = "INSERT INTO Item VALUES (?,?,?,?)";

    try (Connection c = FabricaDeConexao.getConexao();
        PreparedStatement p = c.prepareStatement(comandoSql)) {

      p.setInt(1, item.getCodigo());
      p.setString(2, item.getDescricao());
      p.setDouble(3, item.getPrecoVenda());
      p.setString(4, item.getCategoria().name());

      p.execute();
      return true;

    } catch (SQLException e) {
      return false;
    }
  }
コード例 #2
0
  @Override
  public boolean alterar(Item item) {

    String comandoSql =
        "UPDATE Item SET descricao=?, " + "preco_venda=?,categoria=? WHERE codigo_item=?";

    try (Connection c = FabricaDeConexao.getConexao();
        PreparedStatement p = c.prepareStatement(comandoSql)) {

      p.setString(1, item.getDescricao());
      p.setDouble(2, item.getPrecoVenda());
      p.setString(3, item.getCategoria().name());
      p.setInt(4, item.getCodigo());

      p.execute();
      return true;

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #3
0
  @Override
  public boolean remover(Item item) {

    String comandoSql = "DELETE FROM Item WHERE codigo_item = ?";

    try (Connection c = FabricaDeConexao.getConexao();
        PreparedStatement p = c.prepareStatement(comandoSql)) {

      p.setInt(1, item.getCodigo());

      p.execute();
      return true;

    } catch (SQLException e) {
      return false;
    }
  }