21 July 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 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!");
  }
 }
}

Related Posts:

  • Progress Bar demo thread runnable Demo Progress Thread Runnable package Dmoe; import java.awt.Color; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JProgressBar; import java.awt.event.Act… Read More
  • TEST ADD1 Aptech FPT 2016 Eclipse [TEST ADD1 Aptech fpt - Eclipse] >>Create the program<< How to create JtextArea scrollbar Eclipse? How to create title eclipse? OR userFriendly .java  package us… Read More
  • Connection MsAccessUi in Java Phần 1: Kết nối Microsoft Access bằng Java Nếu bạn sử dụng MS Access 2003(đuôi là .mdb) thì không phải cài đặt thêm Driver Còn nếu như bạn sử dụng MS Access 2007, 20120 (đuôi là .accdb)  thì các bạn cài đặt thêm:… Read More
  • Chooser and save images in eclipse Filechooser images in eclipse Mages.java http://giai-ma.blogspot.com/2016/04/insert-images-to-database-in-mysql.html Sql Serser … Read More
  • Jcalendar Insert Select with Eclipse to Database mysql workbench STEP 1: Download jcalendar-1.4.zip http://www.toedter.com/download/jcalendar-1.4.zip STEP 2: Open jcalendar-1.4.zip STEP3: Extract to workspace  or every where C:\Users\..NamePc..\workspace … Read More

2 nhận xét:

  1. cho xin code bai nay dc k ban?

    ReplyDelete
    Replies
    1. https://giai-ma.blogspot.com/2016/07/project-java-swing-gui-phan-mem-quan-ly.html

      Delete

 

BACK TO TOP

Xuống cuối trang