This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

update query issue  RSS feed

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Thanks
>
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your condition is looking for a username matching ,5101,5102,5103, not three usernames. You need to encapsulate each in quotes.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.How to encapsulate the string in quotes.can you please explain a little bit?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
your query should be like this :



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



 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?>
 
All of the following truths are shameless lies. But what about this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!