Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import javax.sql.ConnectionEvent;
  7. public class BancoDeDados {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. String url = "jdbc:mysql://localhost/loja";
  12. try {
  13.  
  14. Connection conexao = (Connection) DriverManager.getConnection(url);
  15. PreparedStatement pesquisa = (PreparedStatement) conexao.prepareStatement("SELECT * FROM produto");
  16.  
  17. ResultSet resultado = pesquisa.executeQuery();
  18. while (resultado.next()) {
  19. String codigo = resultado.getString("codigo");
  20. String nome = resultado.getString("descricao");
  21. String estoque = resultado.getString("estoque");
  22. String preco = resultado.getString("preco");
  23. System.out.println("Codigo"+codigo+"Descrição:"+nome+"Esoque:"+estoque+"Preço"+preco);
  24.  
  25. }
  26.  
  27. } catch (Exception erro){}
  28.  
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement