私のコードの何が問題なのですか? 2 番目の JcomboBox は、データベースに複数の項目がある場合でも、1 つの項目のみを表示しています。これがどのように機能するかです: 最初の JcomboBox はデータベースからのデータで満たされ、最初のコンボボックスでのユーザーの選択に応じて、2 番目のコンボボックスが満たされ、2 番目の JcomboBox から選択されたアイテムに応じていくつかの Jlabels がデータで満たされます。
if(o ==omboBox2) それでも同じ問題を試しました。
@Override
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if(o == comboBox1) {
Object matricule = comboBox1.getSelectedItem();
String sqll = "Select * FROM clients WHERE matricule = " +matricule;
try {
rs = stat.executeQuery(sqll);
while(rs.next()) {
nom.setText(rs.getString("nom"));
prenom.setText(rs.getString("prenom"));
cin.setText(rs.getString("cin"));
adresse.setText(rs.getString("adresse"));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
comboBox2.removeAllItems();
Object index = comboBox1.getSelectedItem();
String sql = "Select distinct p.code FROM parcelle p, clients c WHERE c.matricule = p.exploitant AND c.matricule = " +index;
try {
rs = stat.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getInt("code"));
comboBox2.addItem(rs.getInt("code"));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return;
}
Object code = comboBox2.getSelectedItem();
String sqll = "Select * FROM parcelle WHERE code = " +code;
try {
rs = stat.executeQuery(sqll);
while(rs.next()) {
sau.setText(rs.getString("sau"));
sol.setText(rs.getString("type_sol"));
irrigation.setText(rs.getString("mode_irrigation"));
exploitation.setText(rs.getString("type_exploitation"));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}