String sql = `"UPDATE User Set address = '" + address +"'
and userType '" + userType +"' WHERE useridNric = '" + id + "'";`
//这不起作用(2个字段).ODBC声明它缺少运算符。
String sql = "UPDATE User Set address = '" + address +"'
WHERE useridNric = '" + id + "'";
//但这有效(1个字段)
希望你们能为2个领域提供帮助.Been尝试使用引号但不能正常工作
答案 0 :(得分:2)
您应该用逗号AND
替换,
以分隔字段分配,否则会出现语法错误(如果分配可以解释为比较,则为逻辑错误):
String sql = "UPDATE User Set address = '" + address +
"', userType ='" + userType +
"' WHERE useridNric = '" + id + "'"; // <<== Rewrite with parameters
不言而喻,您应该使用参数化SQL来避免SQL注入攻击的可能性:
String sql = "UPDATE User Set address = @address, userType = @userType "+
"WHERE useridNric = @id";
答案 1 :(得分:0)
更新多个字段时,请使用逗号分隔:
String sql = "UPDATE User Set address = '" + address +
"', userType ='" + userType +
"' WHERE useridNric = '" + id + "'";
答案 2 :(得分:-1)
使用,
分隔更新查询中的列,如下所示:
String sql = "UPDATE User Set address = '" + address +
"' , userType '" + userType +
"' WHERE useridNric = '" + id + "'";
答案 3 :(得分:-1)
在usertype之后你不需要一个等号
String sql = "UPDATE User Set address = '" + address +"', userType = '" + userType +"' WHERE useridNric = '" + id + "'";