Advertisement
LeonardoProgramador

Mostrar no jComboBox

Aug 24th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1.  try {
  2.             //Registra JDBC driver
  3.             Class.forName("com.mysql.jdbc.Driver");
  4.  
  5.             //Abrindo a conexão
  6. java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pessoas?zeroDateTimeBehavior=convertToNull", "root", "");
  7.             //Executa a query de seleção
  8.             java.sql.Statement st = conn.createStatement();
  9.             st.executeQuery("select * from usuarios");
  10.             ResultSet rs = st.getResultSet();
  11.        
  12.        
  13.  
  14. //...
  15. //...
  16. while(rs.next()){
  17.  jComboBox1.addItem( rs.getString("Nome"));
  18.  }}
  19.         catch (SQLException | ClassNotFoundException e) {
  20.             JOptionPane.showMessageDialog(rootPane, e);
  21.         }
  22.  // Coloca dentro do evento que abre com a janela blz ?
  23. // Vlw !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement