Advertisement
Guest User

Untitled

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