1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| jComboBox1.addItem("----");
String query1 = "SELECT nomregion FROM region";
pst=getCon().prepareStatement(query1);
ResultSet rs1 = pst.executeQuery();
while(rs1.next()) {
jComboBox1.addItem(rs1.getString("nomregion"));
}
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String comboBox1Selected=jComboBox1.getSelectedItem().toString();
try{
String query2 = "SELECT nomdepartement FROM departement, region where "+comboBox1Selected+"";
pst=getCon().prepareStatement(query2);
ResultSet rs2 = pst.executeQuery();
jComboBox2.removeAllItems();
while(rs2.next()) {jComboBox2.addItem(rs2.getString("nomdepartement"));}
JOptionPane.showMessageDialog(null,"nomdepartement");
}
catch (SQLException ex1) {JOptionPane.showMessageDialog(null,"Erreur"+ex1.getLocalizedMessage()); ex1.printStackTrace();
return;}
}
}); |
Partager