SQL 更新查询帮助
我有一个名为“Subject_table”的表..我正在尝试更新该表中的一个字段....但我不断收到语法错误....不确定我做错了。表中的所有字段都是 VARCHAR(30) 类型
这是 queryString 的样子
queryString2 = "update "+tablename+" set tittle='"+tittle+"' , desc='"+desc+"', creditPoints='"+creditPoints+"' where cid='"+cid+"'";
实际查询
UPDATE subject_table
SET tittle='Subject 1', desc='Subject 1', creditPoints='5'
WHERE cid='CSE11111';
我也有删除查询,效果很好...
非常感谢您的帮助..!!! 桌子
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定
desc
未被识别为保留字吗?也许我错了...
试试这个:
在删除查询中,您使用带引号的
desc
...Are you sure that
desc
is not recognized as a reserved word?Maybe I'm wrong...
Try this:
In your delete query you use quoted
desc
...“desc”是一个关键字。尝试将其放在方括号内,如下所示:
"desc" is a keyword. Try putting that within square brackets like this:
语法错误可能来自列名“desc”。
尝试转义此列,并从 where 子句中删除括号。
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.
应该是
where cid='CSE11111'
,而desc
可能是你数据库的保留关键字,尝试用`引用它。Should be
where cid='CSE11111'
, anddesc
maybe the reserved keyword of your database, try to quote it by `.