JcomboBox probleme de doubons

watanabeee Messages postés 8 Statut Membre -  
watanabeee Messages postés 8 Statut Membre -
Bonjour,
J'ai deux jcomboBox, la premiere est remplie depuis une requetes sql, la deuxieme se remplie en fonctient du choix de l'utilisateur.
Une fois le choix sur la deuxieme comboBox fait, des jLabels sont remplies a partir d'une requete sql.

Le probleme c'est que quand je selectionne un choix dans la premiere et que je change ensuite, le 1er choix est toujours présent dans la deuxieme combobox vient s'y ajouter le nouveau choix sans oublier les doubons.

final JComboBox comboBox1 = new JComboBox();
		
		final JComboBox comboBox2 = new JComboBox();
		
		
		try {   	
    		
    		String sql = "Select matricule FROM clients";
			rs = stat.executeQuery(sql);
			comboBox1.addItem("Select item");
			while(rs.next()) {
				comboBox1.addItem(rs.getInt("matricule"));
	    	}
			
			
		} catch (SQLException e) {			
			e.printStackTrace();
		}
		
		comboBox1.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {				 
				 
				int matricule =  (Integer) 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 e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
				String sql = "Select  p.code FROM parcelle p, clients c WHERE c.matricule = p.exploitant AND c.matricule = " +matricule;
				
				try {
					rs = stat.executeQuery(sql);						

					while(rs.next()) {
						
						comboBox2.addItem(rs.getInt("code"));
					}
					
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
				
			}
		});		
		
		
		comboBox1.setBounds(154, 317, 105, 20);
		contentPane.add(comboBox1);		
		
		
		comboBox2.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {			 
	           
				int code =  (Integer) 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 e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		comboBox2.setBounds(154, 423, 105, 20);
		contentPane.add(comboBox2);

1 réponse

watanabeee Messages postés 8 Statut Membre 1
 
quelqu'un svp?
0