Header Ads

Create Employee Management System using JAVA - Part 14

How to Insert-Save data from netbeans java into database Sqlite (MySql)


When click on 'Save' button, the data will save into the table. To do this add following codes to Employee_info.java file.












  • btnSaveActionPerformed - right click on the button --> Events --> Action --> actionPerformed
  • Update_table(); // When you click save button, instantly update the table
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        try{
            PreparedStatement pst = conn.prepareStatement("INSERT INTO employeeinfo (employeeid, name, surname, age) values (?,?,?,?)");        

            pst.setString(1, txt_employeeid.getText());
            pst.setString(2, txt_name.getText());
            pst.setString(3, txt_surname.getText());
            pst.setString(4, txt_age.getText());
         
            pst.executeUpdate();
                     
            // WHEN Data Saved !!!
            JOptionPane.showMessageDialog(null, "Saved!");
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        Update_table();

    }

See you on next tutorial 15 - How To Open New Jframe From A jButton in Netbeans java

No comments

Thank you very much for your ideas!