wood burning stoves 2.0*
The moose likes JDBC and the fly likes doubt in update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "doubt in update" Watch "doubt in update" New topic
Author

doubt in update

Dhivya rajagopal
Ranch Hand

Joined: Dec 15, 2010
Posts: 42
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

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Apr 06, 2010
Posts: 4464
    
    8

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

Joined: Dec 15, 2010
Posts: 42

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

Joined: Jan 08, 2009
Posts: 1478
    
    6

Can we have a look on that code?


Swastik
Dhivya rajagopal
Ranch Hand

Joined: Dec 15, 2010
Posts: 42
The following is the code for submit button

The following is the code for update button:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

It would be better to use PreparedStatement.



Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4464
    
    8

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).
 
Consider Paul's rocket mass heater.
 
subject: doubt in update