By GokiSoft.com| 20:26 14/04/2023|
Java Advanced

Quản lý sinh viên + XML + JSON + MySQL bằng Java

Thiết kế CSDL đặt tên là : quanlysinhvien

Tạo 1 bảng students gồm các thuộc tính : rollno, fullname, gender, email, address

Nhập vào bảng trên ít nhất 3 sinh viên bất kỳ.

Thiết kế phần mềm có giao diện như sau

Khi người dùng nhấn vào button search thực hiện task vụ sau

- Nếu RollNo : để trống thì hiển thị message yêu cầu nhập rollno cần tìm kiếm

- Nếu RollNo : khác rỗng -> thực hiện tìm kiếm sinh viên trong csdl và hiển thị ra các trường trong form

Khi người dùng click reset thì xoá toàn bộ dữ liệu sv trong form

Khi người dùng click vào update thì cập nhật dữ liệu trong CSDL và xoá tất cả các dữ liệu trong form.

- Thiết kế thêm chức năng Import từ XML và JSON => khi click vào chức năng này thực hiện đọc dữ liệu từ file XML hoặc JSON và insert vào CSDL. TH rollNo chưa có thì thêm mới, nếu có rồi thi update

- Thiết kế chức năng Export XML/JSON => Khi click vào chức năng này => show lên dialog cho phép nhập searchValue => thực hiện export sinh viên có tên hoặc rollNo theo dữ liệu searchValue (sử dụng mệ đề like trong câu query)

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

nguyễn văn huy [T1907A]
nguyễn văn huy

2020-04-22 12:18:39



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Swing4;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.json.JSONArray;
import org.xml.sax.SAXException;


/**
 *
 * @author ASUS
 */
public class From extends javax.swing.JFrame {

    DefaultTableModel table;
    List<SinhVien> thaolist = new ArrayList<>();

    /**
     * Creates new form From
     */
    public From() {
        initComponents();
        table = (DefaultTableModel) Tablesinhvien.getModel();
        ShowStudent();
    }

    private void ShowStudent() {
        try {
            thaolist = Modify.Finn();
        } catch (SQLException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        }
        table.setRowCount(0);
        thaolist.forEach((thao) -> {
            table.addRow(new Object[]{table.getRowCount() + 1,
                thao.getRollno(),
                thao.getFullname(),
                thao.getGender(),
                thao.getEmail(),
                thao.getAddress()});
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtRollno = new javax.swing.JTextField();
        txtFullname = new javax.swing.JTextField();
        txtGender = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        btnSeach = new javax.swing.JButton();
        btnImportxml = new javax.swing.JButton();
        btnExportxml = new javax.swing.JButton();
        btnImportjson = new javax.swing.JButton();
        btnExportjson = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tablesinhvien = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("QuanLiSinhVien"));

        jLabel1.setText("Rollno:");

        jLabel2.setText("Fullname:");

        jLabel3.setText("Gender:");

        jLabel4.setText("Email:");

        jLabel5.setText("Address:");

        btnSeach.setText("Seach");
        btnSeach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeachActionPerformed(evt);
            }
        });

        btnImportxml.setText("Import XML");
        btnImportxml.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportxmlActionPerformed(evt);
            }
        });

        btnExportxml.setText("Export XML");
        btnExportxml.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportxmlActionPerformed(evt);
            }
        });

        btnImportjson.setText("Import JSON");
        btnImportjson.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportjsonActionPerformed(evt);
            }
        });

        btnExportjson.setText("Export JSON");
        btnExportjson.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportjsonActionPerformed(evt);
            }
        });

        btnUpdate.setText("Update");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(68, 68, 68)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(121, 121, 121)
                        .addComponent(btnReset, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
                    .addComponent(txtRollno)
                    .addComponent(txtFullname)
                    .addComponent(txtGender)
                    .addComponent(txtEmail)
                    .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 138, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnSeach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnImportxml, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnExportxml, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnImportjson, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnExportjson, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(43, 43, 43))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtRollno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSeach))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtFullname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnImportxml))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnExportxml))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnImportjson))
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnExportjson))
                .addGap(51, 51, 51)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdate)
                    .addComponent(btnReset))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Tablesinhvien.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Rollno", "Fullname", "Gender", "Email", "Address"
            }
        ));
        jScrollPane1.setViewportView(Tablesinhvien);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        String Rollno = txtRollno.getText();
        String Fullname = txtFullname.getText();
        String Gender = txtFullname.getText();
        String Email = txtEmail.getText();
        String Address = txtAddress.getText();
        if (Rollno.isEmpty()) {
            JOptionPane.showMessageDialog(rootPane, "Quen rollno kia bn oiiii");
        }
        SinhVien thao = new SinhVien(Rollno, Fullname, Gender, Email, Address);
        Modify.insert(thao);
        ShowStudent();
    }                                         

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        txtRollno.setText("");
        txtFullname.setText("");
        txtGender.setText("");
        txtEmail.setText("");
        txtAddress.setText("");
    }                                        

    private void btnSeachActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        String rollno = txtRollno.getText();
        if (rollno.isEmpty()) {
            JOptionPane.showMessageDialog(rootPane, "No empty rollno");
            return;
        }
        SinhVien std = Modify.find(rollno);
        if (std == null) {
            JOptionPane.showMessageDialog(rootPane, "Not found any student by rollno");
            return;
        }
        txtFullname.setText(std.getFullname());
        txtEmail.setText(std.getEmail());
        txtAddress.setText(std.getAddress());
        txtGender.setText(std.getGender());
    }                                        

    private void btnImportxmlActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        FileInputStream fis = null;
        try {
            // TODO add your handling code here:

            fis = new FileInputStream("C:\\Users\\ASUS\\Documents\\NetBeansProjects\\Tha.....0\\src\\Swing4\\Student.xml");
            SAXParserFactory fac = SAXParserFactory.newInstance();
            SAXParser sax = fac.newSAXParser();
            huy pa = new huy();
            sax.parse(fis, pa);
            thaolist = pa.giiii();
            table.setRowCount(0);
            for (SinhVien thao : thaolist) {
                table.addRow(new Object[]{
                    thao.getRollno(),
                    thao.getFullname(),
                    thao.getGender(),
                    thao.getEmail(),
                    thao.getAddress()
                });
            }

        } catch (FileNotFoundException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } finally {

            try {
                fis.close();
            } catch (IOException ex) {
                Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

    }                                            

    private void btnExportxmlActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        StringBuilder der = new StringBuilder();
        for (SinhVien thao : thaolist) {
            der.append(thao.getXML());
        }
        String check = der.toString();
        String body = null;
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<studentList>\n"
                + body
                + "\n</studentList>";
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("C:\\Users\\ASUS\\Documents\\NetBeansProjects\\Tha.....0\\src\\Swing4\\Student.xml");
            byte[] data = xml.getBytes();
            fos.write(data);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        JOptionPane.showMessageDialog(rootPane, "Ok bn oiii");
    }                                            

    private void btnImportjsonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        FileReader rea=null;
        
           
        try {
            File file=null;
        JFileChooser fileChooser = new JFileChooser();
            if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                file = fileChooser.getSelectedFile();
                // load from file
            } if(file==null){
                JOptionPane.showMessageDialog(rootPane, "Not file selected");
                return;
            }
            java.lang.reflect.Type classOfT = new TypeToken<ArrayList<SinhVien>>(){}.getType();
            rea = new FileReader(file);
             Gson gson = new Gson();
            ArrayList<SinhVien> list = gson.fromJson(rea, classOfT);
            for (SinhVien thao : thaolist) {
                Modify.insert(thao);
                        
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }                                             

    private void btnExportjsonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
       File file = null;
        
        JFileChooser fileChooser = new JFileChooser();
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
          file = fileChooser.getSelectedFile();
        }
        if(file==null){
        JOptionPane.showMessageDialog(rootPane, "Not save");
            return;
    }
        FileOutputStream fos=null;
        List<SinhVien>thaolist=searchStudents();
        JSONArray aray=new JSONArray(thaolist);
        try {
            fos=new FileOutputStream(file);
            byte[] bii=aray.toString().getBytes();
            fos.write(bii);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                             
    
private List<SinhVien> searchStudents() {
        String searchValue = JOptionPane.showInputDialog("Enter search value");
        
        List<SinhVien> studentList = null;
        
        if(searchValue.isEmpty()) {
            try {
                studentList = Modify.Finn();
            } catch (SQLException ex) {
                Logger.getLogger(From.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            studentList = Modify.findByRollnoOrFullname(searchValue);
        }
        return studentList;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(From.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(From.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(From.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(From.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new From().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTable Tablesinhvien;
    private javax.swing.JButton btnExportjson;
    private javax.swing.JButton btnExportxml;
    private javax.swing.JButton btnImportjson;
    private javax.swing.JButton btnImportxml;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnSeach;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFullname;
    private javax.swing.JTextField txtGender;
    private javax.swing.JTextField txtRollno;
    // End of variables declaration                   
}
>>>>>>>>>>
***************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Swing4;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author ASUS
 */
public class Modify {
    public static List<SinhVien> Finn() throws SQLException{
        List<SinhVien> thaolist=new ArrayList<>();
        Connection conn=null;
        Statement  sta=null;
        try {
            conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/ahihi?serverTimezone=UTC", "root", "");
            String sql="select*from thaomeo";
            sta=conn.createStatement();
            ResultSet resu=sta.executeQuery(sql);
            while (resu.next()) {                
                SinhVien thao=new SinhVien(resu.getString("rollno"),
                        resu.getString("fullname"),
                        resu.getString("gender"),
                        resu.getString("email"),
                        resu.getString("address"));
                thaolist.add(thao);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(conn!=null){
                conn.close();;
            }if(sta!=null){
                sta.close();
            }
        }return thaolist;
    }
    
    public static List<SinhVien> findByRollnoOrFullname(String searchValue) {
        Connection conn = null;
        Statement statement = null;
        List<SinhVien> studentList = new ArrayList<>();
        try {
            //Open connection to Database
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ahihi?serverTimezone=UTC", "root", "");
            
            //query
            String sql = "select * from thaomeo where rollno like '%"+searchValue+"%' or fullname like '%"+searchValue+"%'";
            statement = conn.createStatement();
            
            ResultSet resultSet = statement.executeQuery(sql);
            
            while(resultSet.next()) {
                SinhVien std = new SinhVien(resultSet.getString("rollno"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("gender"), 
                        resultSet.getString("email"), 
                        resultSet.getString("address"));
                studentList.add(std);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        return studentList;
    }
    
        public static void insert(SinhVien thao) {
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            //lay tat ca danh sach sinh vien
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ahihi?serverTimezone=UTC", "root", "");

            //query
            String sql = "insert into thaomeo(rollno,fullname,gender,email,address) values(?, ?, ?, ?,?)";
            statement = connection.prepareCall(sql);

            statement.setString(1, thao.getRollno());
            statement.setString(2, thao.getFullname());
            
            statement.setString(3, thao.getGender());
            statement.setString(4, thao.getEmail());
            statement.setString(5, thao.getAddress());

            statement.execute();
        } catch (SQLException ex) {
            Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        //ket thuc.
    }
    
    public static SinhVien find(String rollno) {
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            //Open connection to Database
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ahihi?serverTimezone=UTC", "root", "");
            
            //query
            String sql = "select * from thaomeo where rollno = ?";
            statement = conn.prepareStatement(sql);
            statement.setString(1, rollno);
            
            ResultSet resultSet = statement.executeQuery();
            
            while(resultSet.next()) {
                SinhVien std = new SinhVien(resultSet.getString("rollno"), 
                        resultSet.getString("fullname"), 
                        resultSet.getString("gender"), 
                        resultSet.getString("email"), 
                        resultSet.getString("address"));
                return std;
            }
        } catch (SQLException ex) {
            Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if(statement != null) {
                try {
                    statement.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Modify.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return null;
    }
    
  
}

>>>>>>>>>
************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Swing4;

/**
 *
 * @author ASUS
 */
public class SinhVien {
     String rollno, fullname, gender, email, address;

    public SinhVien() {
    }

    public SinhVien(String rollno, String fullname, String gender, String email, String address) {
        this.rollno = rollno;
        this.fullname = fullname;
        this.gender = gender;
        this.email = email;
        this.address = address;
    }

    public String getRollno() {
        return rollno;
    }

    public void setRollno(String rollno) {
        this.rollno = rollno;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Students{" + "rollno=" + rollno + ", fullname=" + fullname + ", gender=" + gender + ", email=" + email + ", address=" + address + '}';
    }
    
    public void display() {
        System.out.println(this);
    }
    
    public String getXML() {
        return "<student>\n" +
"		<rollno>"+rollno+"</rollno>\n" +
"		<fullname>"+fullname+"</fullname>\n" +
"		<email>"+email+"</email>\n" +
"		<gender>"+gender+"</gender>\n" +
"		<address>"+address+"</address>\n" +
"	</student>";
    }
}
>>>>>>>>>
*************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Swing4;

import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author ASUS
 */
public class huy extends DefaultHandler {

    List<SinhVien> thaolist = new ArrayList<>();
    SinhVien thao = null;
    boolean isRollno = false,
            isFullname = false,
            isGender = false,
            isEmail = false,
            isAddress = false;

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        if (qName.equalsIgnoreCase("student")) {
         thao=new SinhVien();
        }else if(qName.equalsIgnoreCase("rollno")){
            isRollno=true;
        }else if(qName.equalsIgnoreCase("name")){
            isFullname=true;
        }else if(qName.equalsIgnoreCase("gender")){
            isGender=true;
        }else if(qName.equalsIgnoreCase("email")){
            isEmail=true;
        }else if(qName.equalsIgnoreCase("address")){
            isAddress=true;
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
      if(qName.equalsIgnoreCase("student")){
          thaolist.add(thao);
          thao=null;
      }else if(qName.equalsIgnoreCase("rollno")){
          isRollno=false;
      }else if(qName.equalsIgnoreCase("name")){
          isFullname=false;
      }else if(qName.equalsIgnoreCase("gender")){
          isGender=false;
      }else if(qName.equalsIgnoreCase("email")){
          isEmail=false;
      }else if(qName.equalsIgnoreCase("address")){
          isAddress=false;
      }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
      String value=new String(ch,start,length);
      if(isRollno){
          thao.setRollno(value);
      }else if(isFullname){
          thao.setFullname(value);
      }else if(isGender){
          thao.setGender(value);
      }else if(isEmail){
          thao.setEmail(value);
      }else if(isAddress){
          thao.setAddress(value);
      }
    }
    public List<SinhVien> giiii(){
        return thaolist;
    }

}
>>>>>>>>
&&&&&&&
<?xml version="1.0" encoding="UTF-8"?>
<studentList>
    <student>
        <rollno>R00</rollno>
        <name>thaocho</name>
        <gender>nu</gender>
        <email>t@gmail.com</email>
        <address>null</address>
    </student>
</studentList>