Combobox

2 respostas
java
R

Alguém sabe me dizer porque está repetindo dados nesse ComboBox?

this.CadperfilLinha.removeAllItems();
        this.CadperfilProjeto.removeAllItems();
        try {
            Class.forName(driver);
            Connection con = DriverManager.getConnection(url, user, pass);
            Statement Sent = con.createStatement();
            ResultSet rs = Sent.executeQuery("Select * from Linha, Projeto");
            while (rs.next()) {
                this.CadperfilLinha.addItem(rs.getString("LINHA"));
                this.CadperfilProjeto.addItem(rs.getString("PROJETO"));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }

2 Respostas

staroski

Já conferiu o que seu ResultSet está trazendo?
Tem certeza de que as colunas “LINHA” e “PROJETO” trazem valores diferentes?

R
Resolvido o problema pessoal! ele estava fazendo combinações com duas tabelas. criei uma pra cada. segue o exemplo caso alguém precise.

>         this.CadperfilLinha.removeAllItems();

>         try {

>             Class.forName(driver);

>             Connection con = DriverManager.getConnection(url, user, pass);

>             Statement Sent = con.createStatement();

>             ResultSet rs = Sent.executeQuery(Select * from Linha);

>             while (rs.next()) {

>                 this.CadperfilLinha.addItem(rs.getString(LINHA));

>             }

>         } catch (Exception e) {

>             JOptionPane.showMessageDialog(null, e);

>         }

>

> ////////////////////////////////////////////////////////////////////////////

>

>         this.CadperfilProjeto.removeAllItems();

>         try {

>             Class.forName(driver);

>             Connection con = DriverManager.getConnection(url, user, pass);

>             Statement Sent = con.createStatement();

>             ResultSet rs = Sent.executeQuery(Select * from Projeto);

>             while (rs.next()) {

>                 this.CadperfilProjeto.addItem(rs.getString(PROJETO));

>             }

>         } catch (Exception e) {

>             JOptionPane.showMessageDialog(null, e);

>         }
Criado 11 de maio de 2017
Ultima resposta 12 de mai. de 2017
Respostas 2
Participantes 2