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
|
public boolean reparationTable(int vid_vehicule){
String username = "root";
String password = "";
String url = "jdbc:mysql://localhost/Entretien_Vehicules";
JTable table = new JTable();
table.setBounds(62, 401, 599, -273);
contentPane.add(table);
// TableModel definition
String[] tableColumnsName = {"ID", "N\u00B0 de bon", "Tiers", "Date d'entr\u00E9e", "Date de sortie", "Nature d'activit\u00E9", "Libell\u00E9", "Co\u00FBt", "Description", "Compteur"};
DefaultTableModel aModel = new DefaultTableModel();
aModel.setColumnIdentifiers(tableColumnsName);
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Bloc catch généré automatiquement
e.printStackTrace();
}
try {
Connection connexion = DriverManager.getConnection(url,username,password);
Statement statement=connexion.createStatement();
String sql="SELECT `id`,`num_bon`,`tiers`,`date_entree`,`date_sortie`,`nature_activite`,`libelle`,`cout`,`description`,`compteur`FROM `reparation`WHERE`id_vehicule`="+vid_vehicule+" ";
ResultSet rs= statement.executeQuery(sql);
java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int colNo = rsmd.getColumnCount();
while(rs.next()){
Object[] objects = new Object[colNo];
for(int i=0;i<colNo;i++){
objects[i]=rs.getObject(i+1);
}
aModel.addRow(objects);
}
table.setModel(aModel);
return true;
} catch (SQLException e) {
// TODO Bloc catch généré automatiquement
e.printStackTrace();
return false;
} |
Partager