Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in updating a string variable in database

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • 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
 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just update your code
st.executeUpdate("update queue set causetxt=/""+ cause +"/" where extension='5101'");
 
Navin Loganathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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'");
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
ya true......thnx for the info,,,,,
but it can be used when thr are no quotes within the string
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Navin Loganathan, welcome to JavaRanch

Please don't use abbreviations like "thnx" or "thr"; read this for an explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic