Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. public ArrayList<Produto> ListarProdutos() {
  2.         {
  3.             Produto produto = null;
  4.             ArrayList<Produto> lista = new ArrayList();
  5.             PreparedStatement ps = null;
  6.             try {
  7.                 ps = conn.prepareStatement("SELECT * FROM produto");
  8.                 ResultSet rs = ps.executeQuery();
  9.                 while (rs.next() == true) {
  10.                     produto = new Produto(rs.getInt("CODIGO"),rs.getString("DESCRICAO") , rs.getInt("qtdEstoque"), rs.getFloat("valorUnitario"));
  11.                     System.out.println(produto);
  12.                     lista.add(produto);
  13.                 }
  14.             } catch (SQLException ex) {
  15.                 System.out.println(ex.toString());
  16.             }
  17.             return (lista);
  18.  
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement