Guest User

Untitled

a guest
Jan 3rd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  2.  
  3. String username=jTextField1.getText();
  4. String password=jPasswordField1.getText();
  5. String new_pass=jPasswordField2.getText();
  6. update(1,username,new_pass);
  7. }
  8.  
  9. public void update(int id, String name, String pass) {
  10.  
  11. int i = 0;
  12. try {
  13. Class.forName("com.mysql.jdbc.Driver");
  14. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "root", "");
  15.  
  16. String sql = "UPDATE user_pass SET id=?, password=? WHERE username=? ";
  17. PreparedStatement pst = con.prepareStatement(sql);
  18. pst.setInt(1, id);
  19. System.out.println("Yeha samma thik xa");
  20. pst.setString(2, name);
  21. pst.setString(3, pass);
  22. pst.executeUpdate();
  23. System.out.println("Updated Successifully");
  24. JOptionPane.showMessageDialog(null, "Successifully updated! ");
  25.  
  26. } catch (Exception ex) {
  27. JOptionPane.showMessageDialog(null, "Sorry there is an errornPlease check the information provided ", " ", JOptionPane.ERROR_MESSAGE);
  28. }
  29.  
  30. }
  31.  
  32. catch (Exception ex) {
  33. JOptionPane.showMessageDialog(null, "Sorry there is an errornPlease check the information provided ", " ", JOptionPane.ERROR_MESSAGE);
  34. }
  35.  
  36. String sql=UPDATE user_pass SET id='"+id+"', password='"+password+"' WHERE username='"+username+"' ";
  37.  
  38. } catch (Exception ex) {
Add Comment
Please, Sign In to add comment