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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
public class Modif_Voiture extends javax.swing.JFrame {
private JComboBox jComboBox_voiture;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Modif_Voiture inst = new Modif_Voiture();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public Modif_Voiture() {
super();
initGUI();
}
private void initGUI() {
try {
String nomdsn="DSN_VOITURE";
//on instancie
Connect bdd = new Connect(nomdsn);
//On modifie
try{
String sql = "SELECT * FROM voiture;";
ResultSet Rs = bdd.getStmt().executeQuery(sql);
while (Rs.next()) {
//jComboBox_voiture.addItem(Rs.getString("model"));
System.out.println(Rs.getString("model"));
jComboBox_voiture.addItem(Rs.getString("model"));
}
bdd.close();
}
catch (Exception e) {System.out.println("erreur dans la requete");}
finally {
try{
bdd.close();}
catch (Exception e) {e.printStackTrace();}
}
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
ComboBoxModel jComboBox_voitureModel =
new DefaultComboBoxModel(
new String[] { "Item One"});
jComboBox_voiture = new JComboBox();
getContentPane().add(jComboBox_voiture);
jComboBox_voiture.setModel(jComboBox_voitureModel);
jComboBox_voiture.setBounds(115, 77, 162, 22);
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
} |