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
| private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model=(DefaultTableModel)devoirs.getModel();
try
{
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/etudiant","root","sql");
Statement stmt=con.createStatement();
String query= "Select *from devoirs;";
ResultSet rs =stmt.executeQuery(query);
while(rs.next()){
String inf=rs.getString("info");
String mathematiq=rs.getString("math");
model.addRow(new Object[]{inf,mathematiq});
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(this,"Problème de connexion");
}
} |