Je cherche à afficher le résultat d'une requete SELECT dans des JList
gharsih
Messages postés2Date d'inscriptionmercredi 30 novembre 2011StatutMembreDernière intervention 3 juin 2012
-
23 mai 2012 à 00:19
cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 juillet 2020
-
25 mai 2012 à 09:06
je cherche à afficher le résultat d'une requete SELECT dans des JList voila mon code:
{jComboBox1.removeAllItems();
String[] infos={"Equipement du monteur","Perches d'effort et accessoires","Matériel de protection","Matériel de shuntage et de connexion"};
for(int i=0;i<infos.length;i++)
jComboBox1.addItem(infos[i]);}
}
});
}
return jComboBox;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(401, 24, 90, 14));
jButton.setText("consulter");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Connection connect=null; // connexion avec la base
Statement S=null; // objet d'émission des requêtes
ResultSet RS; // table résultat d'une requête
try{
// connexion à la base
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/gestion_inv","root","");
System.out.println("pppppppppppppppppppppppppppConnexion avec la base gestion inventaire établie");
// création d'un objet Statement
S=connect.createStatement();
String unite = (String)jComboBox.getSelectedItem();
String type = (String)jComboBox1.getSelectedItem();
RS=S.executeQuery("SELECT * FROM matériel WHERE type_matériel='"+type+"'");
System.out.println("type_matériel");
//On affiche le nom des colonnes
int i=0;
// i indique le nombre de ligne
while(RS.next())
{
JList.setModel(model);
String nom=RS.getString();
(DefaultListModel)jList.getModel().add(nom);
}
} catch (Exception e){};
}
});
}
return jButton;
}
public static void main(String args[])
{
new consultation2().setVisible(true);
}