Problemas no ComboBox

4 respostas
D

Pessoal to com problema para inserir as coisas no ComboBox, neste codigo aqui, naum sei se tá faltando algo, mas me ajudem. Ele da erro na linha em negreito

if (jComboBox == null) {
		jComboBox = new javax.swing.JComboBox();
		jComboBox.setSize(115, 18);
		jComboBox.setLocation(90, 98);
		
		JComboBox jcArtista = new JComboBox(); 
		[b]Statement stmt = new Statement();[/b]			ResultSet rs = stmt.executeQuery("SELECT * FROM artista"); 

		Vector valores = new Vector();
// pegando os valores do db

while (rs.next()) {

valores.addElement(rs.getString(artista));

}
// adicionando os valores no JComboBox

for(int i = 0; i < valores.size();i++){

jcArtista.addItem(valores.get(i));

}

4 Respostas

L

kra.

não tenho certeza, mas experimente acrescentar:

private Connection conn;
 private Statement st;

 e ao invés de :

 Statement stmt = new Statement();

  coloque:

  st = conn.createStatement();

Como eu disse eu não tenho certeza, mas não custa tentar

Espero que tenha ajudado!

D

Eu fiz um outro, mas a combo naum aparece, sabem me dizer o pq:

jComboBox.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {  
      
  try{ 
      Conexao con = new Conexao(); 
                   conn = DriverManager.getConnection(dbUrl);
                                   
                   Statement stmt = conn.createStatement(); 
         
                       String dbUrl = "Select * from ARTISTA"; 
      ResultSet rs = stmt.executeQuery(dbUrl); 
           
                   while (rs.next()){ 
                          jComboBox.addItem("" + rs.getString("ARTISTA")+ ""); 
                    } 
                                rs.close(); 
                    stmt.close(); 
                    conn.close();
}catch(Exception f){

f.printStackTrace(System.out);

}

}

});

}
return jComboBox;
D

tente usar um objeto Connection

Connection con = DriverManager.getConnection(url,user,password);
stmt = con.createStatment();

e quando tiver duvidas mande tb o tipo de excecao q foi levantada.

D

Mas o problema é que ele compila normal e passa.
So que na hora que eu rodo ele, ele naum aparece nda
Entendeu, a ComboBox Some

Criado 20 de outubro de 2004
Ultima resposta 20 de out. de 2004
Respostas 4
Participantes 3