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
|
private String[] colonnes = {"N°", "Date", "Obs", "Attribution", "Transmission", " Décision"}; //Les colonnes de la jTable
private Object[][] donnees; //Les données de la jTable
DefaultTableModel model = new DefaultTableModel(donnees, colonnes);
private Statement stmp;
private Connection con;
private PreparedStatement stmt;
private ResultSet rs;
private JComboBox combo = new JComboBox();
private String[] comboData;
//Connection à la Base de Données
String url = "jdbc:mysql://localhost:3306/site";
String identifiant = "root";
try {
con = (Connection) DriverManager.getConnection(url, identifiant, "");
System.out.println("Connexion établie");
} catch (Exception e) {
System.out.println("Erreur lors de la connexion");
}
//Agrandissement des cellules de la jTable
jTable1.getColumnModel().getColumn(0).setPreferredWidth(2);
jTable1.setRowHeight(20);
//Remplissage de la jComboBox
try {
String sql = "SELECT nom, prenom FROM user";
stmt = (PreparedStatement) con.prepareStatement(sql);
rs = stmt.executeQuery(sql);
while (rs.next()) {
combo.addItem(rs.getString(1) + " " + rs.getString(2));
// + AJOUT DANS TABLEAU A FAIRE
}
} catch (Exception e) {
System.out.println("Erreur");
}
//Ajout de la jComboBox dans la jTable
this.jTable1.getColumn("Enquêteur").setCellEditor(new DefaultCellEditor(combo)); |
Partager