• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in updating a string variable in database

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting the output


causetxt='Normal , unspecified'


when i run my java program. I am storing

causetxt='Normal , unspecified'

in a variable "cause".I need to save the value 'Normal,unspecified' in the database table in the column causetxt.But i am unable to store it.when i tried to update this string in the database by using the following query

Instead of causetxt='Normal , unspecified',the value 0 is updated in the column causetxt .Am i doing anything wrong?please assist me to do this.

Thanks
 
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just update your code
st.executeUpdate("update queue set causetxt=/""+ cause +"/" where extension='5101'");
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using this...i have jus added the single quotes before n after cause the double quotes for cause....
st.executeUpdate("update queue set causetxt='"+cause+"' where extension='5101'");
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think your code is not secure
PLease go through this article


 
Navin Loganathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya true......thnx for the info,,,,,
but it can be used when thr are no quotes within the string
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
harilal ithikkat has already pointed you to the right solution.

Follow the link he provided, read the section "Using Parameterized Statements" and apply it in your code.
It will work.

Regards, Jan
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Navin Loganathan, welcome to JavaRanch

Please don't use abbreviations like "thnx" or "thr"; read this for an explanation.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic