SQL Update Query help
I have a table called Subject_table.. I'm trying to update a field in that table.... but i keep getting a syntax error.... Not sure wad i'm doing wrong.开发者_开发问答 All fields in the table are of type VARCHAR(30)
This is what the queryString looks like
queryString2 = "update "+tablename+" set tittle='"+tittle+"' , desc='"+desc+"', creditPoints='"+creditPoints+"' where cid='"+cid+"'";
Actual query
UPDATE subject_table
SET tittle='Subject 1', desc='Subject 1', creditPoints='5'
WHERE cid='CSE11111';
I also have delete query which works fine...
Would appreciate the help..!!! The table
DROP TABLE IF EXISTS `dummy`.`subject_table`;
CREATE TABLE `dummy`.`subject_table` (
`cid` varchar(15) NOT NULL DEFAULT '',
`tittle` varchar(45) NOT NULL DEFAULT '',
`desc` varchar(550) NOT NULL DEFAULT '',
`creditPoints` varchar(45) NOT NULL DEFAULT '',
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Are you sure that desc
is not recognized as a reserved word?
Maybe I'm wrong...
Try this:
UPDATE subject_table
SET tittle='Subject 1', `desc`='Subject 1', creditPoints='5'
WHERE cid='CSE11111';
In your delete query you use quoted desc
...
"desc" is a keyword. Try putting that within square brackets like this:
update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111');
The syntax error might be coming from the column name "desc".
Try escaping this column, as well as removing the brackets from the where clause.
update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111');
Should be where cid='CSE11111'
, and desc
maybe the reserved keyword of your database, try to quote it by `.
精彩评论