JcomboBox ne montre q'un seul item

JcomboBox ne montre q'un seul item - Java - Programmation

Marsh Posté le 29-05-2012 à 21:10:37    

Bonsoir,
 
Qu'est ce qui ne va pas avec mon code? La deuxième JcomboBox ne montre qu'un seul item même s'il y a plus dans la base de donnée.
 

Code :
  1. @Override
  2. public void actionPerformed(ActionEvent e) {
  3.  Object o = e.getSource();
  4.  if(o == comboBox1) {
  5.   Object matricule =  comboBox1.getSelectedItem();
  6.   String sqll = "Select  * FROM clients WHERE matricule = " +matricule;
  7.    try {
  8.     rs = stat.executeQuery(sqll);
  9.     while(rs.next()) {
  10.      nom.setText(rs.getString("nom" ));
  11.      prenom.setText(rs.getString("prenom" ));
  12.      cin.setText(rs.getString("cin" ));
  13.      adresse.setText(rs.getString("adresse" ));
  14.     }
  15.    } catch (SQLException e1) {
  16.     // TODO Auto-generated catch block
  17.     e1.printStackTrace();
  18.    }
  19.   comboBox2.removeAllItems();
  20.   Object index = comboBox1.getSelectedItem();
  21.   String sql = "Select  distinct p.code FROM parcelle p, clients c WHERE c.matricule = p.exploitant AND c.matricule = " +index;
  22.    try {
  23.     rs = stat.executeQuery(sql);
  24.     while(rs.next()) {
  25.      System.out.println(rs.getInt("code" ));
  26.      comboBox2.addItem(rs.getInt("code" ));
  27.     }
  28.    } catch (SQLException e1) {
  29.     // TODO Auto-generated catch block
  30.     e1.printStackTrace();
  31.    }
  32.   return;
  33.  }
  34.              Object code =  comboBox2.getSelectedItem(); 
  35.              String sqll = "Select  * FROM parcelle WHERE code = " +code; 
  36.              try
  37.                  rs = stat.executeQuery(sqll);                   
  38.                  while(rs.next()) { 
  39.                      sau.setText(rs.getString("sau" )); 
  40.                      sol.setText(rs.getString("type_sol" )); 
  41.                      irrigation.setText(rs.getString("mode_irrigation" )); 
  42.                      exploitation.setText(rs.getString("type_exploitation" ));                     
  43.                  } 
  44.              } catch (SQLException e1) {
  45.     // TODO Auto-generated catch block
  46.     e1.printStackTrace();
  47.   }
  48. }

Reply

Marsh Posté le 29-05-2012 à 21:10:37   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed