• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in update

 
Dhivya rajagopal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created 2 forms using swing in netbeans.first form helps to store the data entered in the form. second form contains 2 labels such as username and password, 2 textboxes and 2 buttons such as submit and update. if i click submit button , it checks the data entered with the database and if it matches, it display the dialog box-"Successfully". if i give new password and click update button,it should be updated.Here, is the program used for updating

My doubt is if i click update button , it displays Updated successfully, but it is not stored in the database. can you please tell why it is not storing?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhivya rajagopal wrote:I have created 2 forms using swing in netbeans.first form helps to store the data entered in the form. second form contains 2 labels such as username and password, 2 textboxes and 2 buttons such as submit and update. if i click submit button , it checks the data entered with the database and if it matches, it display the dialog box-"Successfully". if i give new password and click update button,it should be updated.Here, is the program used for updating

My doubt is if i click update button , it displays Updated successfully, but it is not stored in the database. can you please tell why it is not storing?
Is the database supposed to be storing the password as plain text rather than with the password() function? That seems odd.
Have you printed the rs value? Does it confirm you are actually updating anything?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have got the order of the name and password the wrong way round. You're binding the contents of jPasswordField1 to the second parameter of the query, which is the name. So the UPDATE runs without error, but doesn't match against any records.
 
Dhivya rajagopal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you brown and ritchie, now its updating. For example I gave dhivya in username and mita in text box and click update means it is store in the database. That form contains submit button, it checks for the data entered in the text box with the databases and if it matches then it will display "successful". if it doesn't match, then it will display "enter valid username and password".
after updating , if i give the same value in the textboxes and click submit button means it is displaying "enter valid username and password".can you tell me why?
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we have a look on that code?
 
Dhivya rajagopal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the code for submit button

The following is the code for update button:
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better to use PreparedStatement.



 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not related to your question - but why are you using an int as a flag? This is Java - it's got a boolean type for that sort of thing.

Swastik's right, though. It's much better to query exactly the record you need than it is to get all the users and loop round all of them.

(Edit: by the way, the reason your code is formatted poorly is that you're using a mixture of tabs and spaces. I'd recommend switching to using spaces all the time. A couple of the lines also had a huge number of spaces at the end of them, which was why it was messing up the page width here. I've removed them to stop that happening).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic