Advertisement
Guest User

SaveButton

a guest
Feb 22nd, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. try {
  2. Class.forName("com.mysql.jdbc.Driver");
  3. Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee", "root", "");
  4. PreparedStatement pt = connect.prepareStatement("INSERT INTO employee (firstname,lastname,deptcode,phoneno,hiredate,job) values(?,?,?,?,?,?)");
  5.  
  6.  
  7. pt.setString(1, fnameTField.getText());
  8. pt.setString(2, lnameTField.getText());
  9. pt.setString(3, deptCodeCombo.getSelectedItem().toString());
  10. pt.setString(4, phoneTField.getText());
  11. pt.setString(5, hiredateTField.getText());
  12. pt.setString(6, jobTField.getText());
  13.  
  14. pt.executeUpdate();
  15. connect.close();
  16. JOptionPane.showMessageDialog(this, "New Employee Save!", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
  17.  
  18. fnameTField.setText(null);
  19. lnameTField.setText(null);
  20. deptCodeCombo.setSelectedIndex(0);
  21. hiredateTField.setText(null);
  22. phoneTField.setText(null);
  23. jobTField.setText(null);
  24.  
  25.  
  26. NewRecord.setVisible(false);
  27.  
  28. } catch (SQLException sqe) {
  29. JOptionPane.showMessageDialog(this, "SQl error!", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
  30. System.out.println("SQl error: " + sqe.toString());
  31.  
  32. } catch (ClassNotFoundException cnf) {
  33. System.out.println("Class not found error: " + cnf.toString());
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement