ComboBox et Access

rytta87 Messages postés 26 Date d'inscription lundi 3 juillet 2006 Statut Membre Dernière intervention 5 mars 2009 - 28 déc. 2006 à 21:54
hafedhaouni Messages postés 62 Date d'inscription jeudi 18 février 2010 Statut Membre Dernière intervention 16 février 2012 - 27 juin 2009 à 00:40
Salut,

J'aimerais avoir une méthode pour charger le contenu d'une colonne d'une table Access dans un JComboBox. J'ai déjà utilisé le code suivant mais ça n'a pas marché:

public

String ChargerIDChambre(
int num){ResultSet rs;

try {

//Exécution de la requêteStatement st =

conn.createStatement();String myquery=

"SELECT IDChambre " +

"FROM TChambre "+

"WHERE NumChambre="+num;

rs = st.executeQuery(myquery);

rs.next();

return rs.getString(1);

}

catch (Exception e) {System.

out .println(e.toString());

return
"";}

}

private

JComboBox getJComboBoxIDChambre() {

if (
jComboBoxIDChambre ==
null ) {

jComboBoxIDChambre =
new JComboBox();

jComboBoxIDChambre.setBounds(
new Rectangle(132, 26, 224, 20));

int k;

for(k=1;k<=20;k++){ //sachant qu'il y a 20 chambres numérotées de 1 à 20String IDChamb = ChargerIDChambre(k);

jComboBoxIDChambre.addItem(IDChamb);}}

return
jComboBoxIDChambre;}

Merci

1 réponse

hafedhaouni Messages postés 62 Date d'inscription jeudi 18 février 2010 Statut Membre Dernière intervention 16 février 2012 1
27 juin 2009 à 00:40
private boolean bSqlDefined;
public Table(String name, int nbKey) {
        super(name, nbKey);
        this.name = name;
        bSqlDefined = false;
        update();
    }

private DefaultComboBoxModel cModel;
protected void initClient() {
        cModel = new DefaultComboBoxModel();
        Table t;
        t = new Table("Client", 1);
        t.remplirModel(cModel);
        jComboNom.setModel(cModel);
    }
0
Rejoignez-nous