File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes update query issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "update query issue " Watch "update query issue " New topic

update query issue

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518

I have field username with datas like 5101,5102,5103 in a table "cc_dailylog". I have a list box in my jsp page which displays all these usernames. If i select more than 1 username and tried to update a campaign "Aircel" for all the username,i am unable to update. so i tried to split the username with comma and put it in a loop and tried to update the campaign "Aircel" for all the usernames like the following:

when i try to run the code the print statement prints the following and nothing is updated.

update cc_dailylog set campaign='Aircel' where username in(',5101,5102,5103')

When i tried to execute the above directly in phpmyadmin, it also shows error. Then how can i update more than 1 username and update the value "Aircel" for all these usernames.Please assist me to do this.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Your condition is looking for a username matching ,5101,5102,5103, not three usernames. You need to encapsulate each in quotes.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks.How to encapsulate the string in quotes.can you please explain a little bit?
Hrishikesh Hemade

Joined: Mar 17, 2005
Posts: 9
Hi ,
your query should be like this :

you need to modify your for loop to add single quote.

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I have added like the following with the tmp:

for(int i=0;i<username.length;i++){
String tmp1=tmp+","+"'"+username[i];

But the printed query is

update cc_dailylog set campaign='Aircel' where username in (','5101,'5102,'5103');

Where am i wrong?>
I agree. Here's the link:
subject: update query issue
Similar Threads
Well, since no one asked them on their own, here are one's I posted earlier
problem in passing while loop variables from database
error in update query
Error on threads
Web App hangs up when opening hibernate session factory