Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 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("UPDATE employee SET firstname=?, lastname=?, deptcode=?, phoneno=?, job=? where empno = " + empnoTField1.getText()) ;
  6.  
  7. if(JOptionPane.showConfirmDialog(null, "Are you sure to update this employee?", "Confirm Update?", JOptionPane.YES_NO_OPTION) == 0){
  8.  
  9. // pt.setString(1, empnoTField1.getText());
  10. pt.setString(1, fnameTField1.getText());
  11. pt.setString(2, lnameTField1.getText());
  12. pt.setString(3, deptCodeCombo1.getSelectedItem().toString());
  13. pt.setString(4, phoneTField1.getText());
  14. // pt.setString(6, hiredate1.getText());
  15. pt.setString(5, jobTField1.getText());
  16.  
  17. pt.executeUpdate();
  18. connect.close();
  19. UpdateRecord.setVisible(false);
  20. displayTable();
  21. }
  22.  
  23.  
  24. }
  25. catch(SQLException sqe){
  26. System.out.println("SQl error: " + sqe.toString());
  27. }
  28. catch(ClassNotFoundException cnf){
  29. System.out.println("Class not found error: " + cnf.toString());
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement