Header Ads

Create Employee Management System using JAVA with SQLite - Part 09

Get value from JTable and set it to jtextfield in Netbeans Java and Sqlite






















Right click on the Design of the table à Events à Mouse àmouseClicked, it will show the method to do this. Add this code there to get the desire output.

txt_employeeid  - we set that variable name to the text field which we have added previously and other variable are same as the follows.
private void table_employeeMouseClicked(java.awt.event.MouseEvent evt) {                                           
        // TODO add your handling code here:
        try{
            int row = table_employee.getSelectedRow();
            String Table_click = (table_employee.getModel().getValueAt(row, 0).toString());
            PreparedStatement pst = conn.prepareStatement("SELECT * FROM employeeinfo WHERE employeeid = '"+Table_click+"'");
            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);
        }
    }

Output:





















In next part we will discuss about ‘get values to jtext field when click a value on jcombo box’ by using Java. If you have any doubts about the part – 09 please don’t hesitate to ask from iTech Digest | Thank you! See you on part - 10

No comments

Thank you very much for your ideas!