SHARE
TWEET

duartiiiiiiiiiiiii

a guest May 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package br.edu.ifms.vendas.DAO;
  7.  
  8. import br.edu.ifms.vendas.modelo.Vendas;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. /**
  16.  *
  17.  * @author famil
  18.  */
  19. public class VendasDAO {
  20.     public static void inserir(Vendas venda){
  21.         String sql = "INSERT INTO vendas (tipopag,id,codigo,descricao,qtd,precou) "
  22.                 + "VALUES (?,?,?,?)";
  23.         try{
  24.         PreparedStatement pstm =
  25.                 new Conexao().fazerConexao().prepareStatement(sql);
  26.         pstm.setObject(1, venda.getTipopag());
  27.         pstm.setObject(2, venda.getId());
  28.         pstm.setObject(3, venda.getCodigo());
  29.         pstm.setObject(4, venda.getDescricao());
  30.         pstm.setObject(5, venda.getQtd());
  31.         pstm.setObject(6, venda.getPrecou());
  32.         pstm.executeQuery();
  33.         pstm.close();
  34.             System.out.println("Venda Inserida com sucesso!!");
  35.        
  36.         }catch(SQLException ex){
  37.             System.out.println("Problemas ao inserir informações da sua venda");
  38.             System.out.println(ex.getMessage());
  39.         }
  40.         }
  41.     public static List<Vendas> buscarVendas(){
  42.          List<Vendas> vendas = new ArrayList();
  43.          
  44.          String sql = "SELECT * FROM vendas";
  45.          try{
  46.          PreparedStatement pstm =
  47.                  new Conexao().fazerConexao().prepareStatement(sql);
  48.          
  49.          ResultSet rs = pstm.executeQuery();
  50.          while(rs.next()){
  51.              Vendas venda = new Vendas();
  52.              venda.setTipopag(rs.getInt("tipopag"));
  53.              venda.setId(rs.getInt("id"));
  54.              venda.setCodigo(rs.getInt("codigo"));
  55.              venda.setDescricao(rs.getString("descricao"));
  56.              venda.setQtd(rs.getInt("qtd"));
  57.              venda.setPrecou(rs.getDouble("precou"));
  58.              vendas.add(venda);
  59.          }
  60.          rs.close();
  61.          
  62.          }catch(SQLException ex){
  63.              System.out.println("Problemas ao ler informação do banco");
  64.          }
  65.          
  66.          return vendas;
  67.     }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top