Estou com um banco no mysql = registrando os motivos para baixa! quero carregar o meu CBmotivo no netbeans com o mysql!

2 respostas
programação
E

Banco
int = idfun
String = motinvo

public void PesquisaSetor() {

String sql =select func.MOTIVO from func order by MOTIVO;

try {
pst = conexao.prepareStatement(sql);
        rs = pst.executeQuery();
        
        while (rs.next()) {
           cbmotivo.addItem(rs.getString("motivo"));
        }
        rs.close();
        
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Ocorreu erro ao carregar a Combo Box", "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}

2 Respostas

H

Amigo, se entendi bem, acho que assim vai funcionar:

public void PesquisaSetor() {

String sql =select * from func order by MOTIVO;
try {
        pst = conexao.prepareStatement(sql);
        rs = pst.executeQuery();
        
        while (rs.next()) {
           String mot = rs.getString("motivo");
          cbmotivo.addItem(mot);
        }
        rs.close();
        
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Ocorreu erro ao carregar a Combo Box", "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}
E

Obrigado
Vou dar uma olhada lá ver o que consigo !!!

Criado 26 de fevereiro de 2021
Ultima resposta 3 de mar. de 2021
Respostas 2
Participantes 2