Sunday, December 4, 2016
Hà m xóa dữ liá»u vá»i Jcheckbox trong Jtable Delete checkbox table Java Swing Gui Eclipse
Hà m xóa dữ liá»u vá»i Jcheckbox trong Jtable Delete checkbox table Java Swing Gui Eclipse




Hàm xóa d? li?u table khi dùng checkbox
Java 2016
public void deleteSinhVien(JTable table){
boolean tich = false;
Object[] options = { "Yes", "No" };
int n = JOptionPane.showOptionDialog(null, "B?n có mu?n xóa d? li?u này không?", "Confirm to Delete?",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
if (n == 0) // Confirm Delete = Yes
{
for (int i = 0; i < table.getRowCount(); i++) {
Boolean chkDel = Boolean.valueOf(table.getValueAt(i, 0).toString()); // Checked
if (chkDel) // Checked to Delete
{
// Delete Data
String sql = "DELETE FROM project.sinhvien WHERE idsv = ?";
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, table.getValueAt(i, 1).toString());
stmt.executeUpdate();
tich = true;
} catch (Exception ed) {
JOptionPane.showMessageDialog(null, "Không th? xóa id "
+ table.getValueAt(i, 1).toString() + " vui lòng xem l?i b?ng ?i?m");
tich = false;
}
}
}
if (tich) {
JOptionPane.showMessageDialog(null, "Xóa d? li?u thành công!");
}
}
}
Available link for download