Header Ads

Create Employee Management System using JAVA - Part 20

How to search a particular data inSQLite (MySql) Database in Netbeans java jtable
Add a Text Field --> txt_search

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);
        }
    }

When you type a name in Search text filed, you can view data.

See you on next tutorial 21 -Advanced  search a particular data inSQLite (MySql) Database in Netbeans java jtable!

No comments

Thank you very much for your ideas!