简体   繁体   English

使用一个表中的多个字段更新SQL语句

[英]Update SQL statement with multiple fields within ONE table

I am trying to write an update SQL statement for many columns within one table only. 我试图只为一个表中的许多列编写一条更新SQL语句。 For example product table. 例如产品表。 Within product table, there are many columns like name, description, price, quantity, image, category, status. 在产品表中,有很多列,例如名称,描述,价格,数量,图像,类别,状态。

So I came out with this SQL statement: 因此,我得出了以下SQL语句:

String sql = "UPDATE sm_product SET productDescription = '" + desc +
    "' , productPrice = ' + price + ', productQuantity = ' + quantity +
    ', productImage = '" + image + "', productCategory = '" + category +
    '"  WHERE productName = '" + name + "'";

However, the compiler told me that there are unclosed character literal and not a statement. 但是,编译器告诉我,有未封闭的字符文字,而不是语句。 I wonder how should I fix this SQL statement because I only have one table to update. 我不知道应该如何解决此SQL语句,因为我只有一个表要更新。 But within that table, there are many fields. 但是在该表中,有许多字段。

Thanks in advance. 提前致谢。

It looks like you have problems with your quotes. 看来您的报价有问题。 Try this: 尝试这个:

String sql = "UPDATE sm_product SET productDescription = '" + desc +
    "' , productPrice = " + price + ", productQuantity = " + quantity +
    ", productImage = '" + image + "', productCategory = '" + category +
    "'  WHERE productName = '" + name + "'";

This is assuming that price and quantity are numeric and the rest are strings. 假设价格和数量为数字,其余为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM