I have data from the database on my JTable
. I want to add checkboxes to each row dynamically from the database. I will later use these checkboxes to delete rows checked from the database. I know how to delete from the database, but how to add checkboxes from the database? Any one done this before please help. I am a Java enthusiast trying to learn it. A sample code could help me understand how to do this.
Code below is for updating my JTable
:
public void UpdateTable() {
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"
+ "employee_certificate", "root", "");
String sql = "SELECT certificate.Number, staff.Emp_Id, staff.Emp_Name, "
+ "staff.Department, certificate.Cert_Code, certificate.Cert_Name,\n"
+ "certificate.Vendor, certificate.Date_Taken, "
+ "certificate.Expiry_Date FROM staff LEFT JOIN certificate"
+ " ON staff.Emp_Id=certificate.Emp_Id ORDER BY staff.Emp_Name\n";
PreparedStatement pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}