Example #1
0
  public void inserir(Pessoa pessoa) {
    try {
      conexao = ConexaoMySQL.abrirConexao();
      PreparedStatement ps =
          conexao.prepareStatement("insert into pessoa (nome, cpf, rg) values(?,?,?)");

      ps.setString(1, pessoa.getNome());
      ps.setString(2, pessoa.getCpf());
      ps.setString(3, pessoa.getRg());

      ps.executeUpdate();
      ps.close();
      conexao.close();
    } catch (SQLException ex) {
      Logger.getLogger("PessoaDAO").log(Level.SEVERE, "SQLException: {0}", ex.getMessage());
    }
  }
  public int buscarIdForma(String nome) {
    Connection con;
    PreparedStatement stmt;

    try {
      con = ConexaoMySQL.conectar();
      stmt = con.prepareStatement(SQL_BUSCAR_FORMA_PAGAMENTO_DESCRICAO);
      stmt.setString(1, nome);
      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        return rs.getInt("idforma_pagamento_compra");
      }
      con.close();
    } catch (SQLException ex) {
    }
    return 0;
  }
  public String buscarNomeForma(int id) {
    Connection con;
    PreparedStatement stmt;

    try {
      con = ConexaoMySQL.conectar();
      stmt = con.prepareStatement(SQL_BUSCAR_FORMA_PAGAMENTO_ID);
      stmt.setInt(1, id);
      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        return rs.getString("descricao");
      }
      con.close();
    } catch (SQLException ex) {
    }
    return "Erro";
  }
  public ArrayList<FormaPagamento> buscarFormaPagamento() {
    ArrayList<FormaPagamento> formaPagamentos = new ArrayList<FormaPagamento>();
    String query = SQL_BUSCA_FORMA_PAGAMENTO;

    try {
      ResultSet rs = ConexaoMySQL.getInstance().executeQuery(query);
      while (rs.next()) {
        FormaPagamento formaPagamento = new FormaPagamento();
        formaPagamento.setIdformaPAgamento(rs.getInt("idforma_pagamento_compra"));
        formaPagamento.setDescricao(rs.getString("descricao"));
        formaPagamento.setTipoDePagamento(rs.getInt("tipo"));
        formaPagamentos.add(formaPagamento);
      }
    } catch (SQLException ex) {
      System.out.println(ex.getMessage());
    }
    return formaPagamentos;
  }
Example #5
0
  public int buscarId() {

    int maiorId = 0;

    try {
      conexao = ConexaoMySQL.abrirConexao();
      Statement ps = conexao.createStatement();

      ResultSet rs = ps.executeQuery("select max(idPessoa) from pessoa");

      while (rs.next()) {
        maiorId = rs.getInt("idPessoa");
      }

      ps.close();
      rs.close();
      conexao.close();
    } catch (SQLException ex) {
      Logger.getLogger("UsuarioDAO").log(Level.SEVERE, "SQLException: {0}", ex.getMessage());
    }

    return maiorId;
  }
Example #6
0
  public Pessoa buscar(Pessoa pessoa) {
    try {
      conexao = ConexaoMySQL.abrirConexao();
      PreparedStatement ps =
          conexao.prepareStatement("select nome, cpf, rg from pessoa where cpf = ?");
      ps.setString(1, pessoa.getNome());

      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        pessoa.setNome(rs.getString("nome"));
        pessoa.setRg(rs.getString("telefone"));
        pessoa.setCpf(rs.getString("email"));
      }
      rs.close();
      ps.close();
      conexao.close();
    } catch (SQLException ex) {
      Logger.getLogger("ClienteDAO").log(Level.SEVERE, "SQLException: {0}", ex.getMessage());
    }

    return pessoa;
  }