Header Ads

Create Employee Management System using JAVA - Part 21


Advanced  search a particular data inSQLite (MySql) Database in Netbeans java jtable
In the event (20) that we have created Search, it will not give a search result under employeeid or surname.
Add this code after the the catch code. In the SELECT query you can give employeeid and surname. Then search will be optimal when you searching under these categories.

private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
        try{
            PreparedStatement pst = conn.prepareStatement("SELECT * FROM employeeinfo WHERE name=?");
            pst.setString(1, txt_search.getText());
           
            rs = pst.executeQuery();
            if(rs.next()){
                String add1 = rs.getString("employeeid");
                txt_employeeid.setText(add1);
                String add2 = rs.getString("name");
                txt_name.setText(add2);
                String add3 = rs.getString("surname");
                txt_surname.setText(add3);
                String add4 = rs.getString("age");
                txt_age.setText(add4);
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }

try{
            PreparedStatement pst = conn.prepareStatement("SELECT * FROM employeeinfo WHERE surname=?");
            pst.setString(1, txt_search.getText());
         
            rs = pst.executeQuery();
            if(rs.next()){
                String add1 = rs.getString("employeeid");
                txt_employeeid.setText(add1);
                String add2 = rs.getString("name");
                txt_name.setText(add2);
                String add3 = rs.getString("surname");
                txt_surname.setText(add3);
                String add4 = rs.getString("age");
                txt_age.setText(add4);
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }

See you on next tutorial 22 -Using Up-Down Arrow Key to Move in a jtable and get the Data in jtextfield  netbeans!

No comments

Thank you very much for your ideas!