*
The moose likes JDBC and the fly likes problem in updating a string variable in database 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 "problem in updating a string variable in database" Watch "problem in updating a string variable in database" New topic
Author

problem in updating a string variable in database

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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

Joined: Dec 18, 2008
Posts: 164

Just update your code
st.executeUpdate("update queue set causetxt=/""+ cause +"/" where extension='5101'");


Java Best Practices
Linux Best Practices
Amortization Calculator

Navin Loganathan
Greenhorn

Joined: Mar 11, 2009
Posts: 2
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

Joined: Oct 06, 2008
Posts: 221
i think your code is not secure
PLease go through this article




SCJP 1.5
"A candle looses nothing by lighting another candle"
itechmentors.com
Navin Loganathan
Greenhorn

Joined: Mar 11, 2009
Posts: 2
ya true......thnx for the info,,,,,
but it can be used when thr are no quotes within the string
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Navin Loganathan, welcome to JavaRanch

Please don't use abbreviations like "thnx" or "thr"; read this for an explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in updating a string variable in database
 
Similar Threads
Getting numeric data from VARCHAR2 type
questions on entity bulk operations
null values on the update data
SQL Exception:General Error
SQL exception