Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't update password from Swing app  RSS feed

 
wee long ong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue has been resolved, but another issue with my password is i'm unable to update my password through database. I can successfully change my password on my client side effect. but it does not reflect to the database.

Here's my code

Passchange.java


My database method for update password

 
Paul Clapham
Sheriff
Posts: 22267
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that your code doesn't commit the change. Do you have auto-commit turned on?
 
Ron McLeod
Saloon Keeper
Posts: 1527
210
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seem like there is something wrong with the logic - you are setting the new password in uData after you have tried to update the password rather than before, so you will be UPDATEing the database record with the current password, not the new one.


 
wee long ong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paul,

my auto-commit is turned on,

hi ron,

so there's nothing wrong with my database method? I did some of the research, i still figuring out how do i update the current password.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37051
507
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron suggested your code isn't correct. Look at this line:


Now look at where uData is getting set up. Does it contain the new password? (It doesn't look that way.) Why not?
 
wee long ong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is because I called out the wrong parameter? I've change the parameter matching with the database parameter method it would throw me an error.
 
Ron McLeod
Saloon Keeper
Posts: 1527
210
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For debugging, add a couple of print statements to show what values you are providing to your updatePassword method, and verify they are what you are expecting
 
wee long ong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ron,

it seem that it only retrieve the userid and the password. it doesn't make any changes. Could you illustrate how do i make it change in my method? Or give a rough explanation.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37051
507
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't follow whether the error is that the println is showing the old or new password. Can you explicitly state which case it is?
 
wee long ong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shows the old password
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37051
507
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The good news is that this isn't a database problem. It's a Swing problem so I've added this post to our Swing forum.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37051
507
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now back to your problem. Let's take a look at what happens here:



This code:
  • Gets the new password and puts it in a local variable
  • Calls the method to update the password
  • Method still has old password in udata so doesn't work


  • The call to uData.setPassword(password) is AFTER the attempted database update. You'll need to move it before the if statement.
     
    wee long ong
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh dear, i don't know why just one line of code, it got me over 24 hour to find what's the issue. The issue has been resolved. Anyway, how do i let the user to put in their current password for the confirmation? Don't mind writing in bullet point? Thanks!!!
     
    Jeanne Boyarsky
    author & internet detective
    Marshal
    Posts: 37051
    507
    Eclipse IDE Java VI Editor
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You had them enter the current password. You'll need a select query to confirm it matches the database.
     
    wee long ong
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you, The whole issue has been resolved. Can i leave a feedback on you or the forum?
     
    Jeanne Boyarsky
    author & internet detective
    Marshal
    Posts: 37051
    507
    Eclipse IDE Java VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Great, I've marked this as resolved.

    There's a like button that you can use to indicate that a post is helpful.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!