Header Ads

Create Employee Management System using JAVA with SQLite - Part 10

Display data in jtextfield when select item in jcombobox in Netbeans Java and Sqlite






















In our previous tutorial we discussed about how to view data in the text fields when we select some data on jTable. So now you have an idea about how it happens and at here we believe that you don't want more instructions to code this.
Go to Employee_info.java file and right click on the jcombo box which you have added already into the design. Then go to Events --> PopupMenu --> PopupMenuWillBecomeInvisible. Now you get down to the the source file. Then you have to add this code to run the program.

private void ComboBox_namePopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {                                                          
        // TODO add your handling code here:
        String tmp = (String)ComboBox_name.getSelectedItem();
        try{
            PreparedStatement pst = conn.prepareStatement("SELECT * FROM employeeinfo WHERE name=?");
            pst.setString(1, tmp);
            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);
        }
    }    

Now you ready to run the program.

In next part we will discuss about 'How to create & use jmenubar, jmenuitem,jtoolbar,JSeparato’ by using Java. If you have any doubts about the part – 10 please don’t hesitate to ask from iTech Digest | Thank you! See you on part - 11

No comments

Thank you very much for your ideas!