permaculture playing cards*
The moose likes JDBC and the fly likes Update the whole info in database instead of one. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Update the whole info in database instead of one." Watch "Update the whole info in database instead of one." New topic
Author

Update the whole info in database instead of one.

Loh Peggie
Ranch Hand

Joined: Jul 09, 2009
Posts: 51
Hey guys, I have a problem regarding on updating in database using jsp and servlets.

The problem is when I update it will update the whole records instead on the specific records I choose to update. Like I update yellow beanie color from "green to yellow".
It update all the color to be the same one as well as other details

do you know what happen?

This is my code in servlet:



This is my update form in jsp using dojox



Thanks for your help in all this while.

I really appreciate it
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

What is the primary key for the table you are updating ?

is it UserId or ProductId ?

Since you are saying that update is working, so, it seems to be a problem with the query.




Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Loh Peggie
Ranch Hand

Joined: Jul 09, 2009
Posts: 51
Oh the primary key is ProductId
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Change your query to



If you want to update products based on userid then


This will solve your issue..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Please be sure to ask JDBC questions in the JDBC forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Loh Peggie
Ranch Hand

Joined: Jul 09, 2009
Posts: 51
Thank you.

Howerver there seems to be error. It explains that :Syntax error on token(s), misplaced construct(s)
, when I debug

Is there anything wrong with this?



Thanks for your help all this while
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Loh,
The prepared statement code looks fine. It's much more likely the error is in your SQL string. Can you post the updated one you are using?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Loh Peggie
Ranch Hand

Joined: Jul 09, 2009
Posts: 51
Yeah sure

This is the one i am currently using




Is this the correct statement that allows me to update all value regarding on product except UserId
However when I update it will show something Syntax error on token(s), misplaced construct(s) when I debug
Thanks
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Hmm. The SQL looks right. You might try moving the "set" for parameter 8 to the end. There's no rule that says they have to be set in order, but you never know.

As far as debugging goes, does it work if you just update one column? Two columns? etc. Finding the smallest statement that gives the error will help in narrowing it down.
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Perhaps you have to remove the 'space' inside your PreparedStatement..

please try this Statement..


Correct me if im wrong..

Hope this help..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
 
 
subject: Update the whole info in database instead of one.