user2424370
user2424370

Reputation:

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. 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:

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. But within that table, there are many fields.

Thanks in advance.

Upvotes: 0

Views: 84

Answers (1)

Tom
Tom

Reputation: 6663

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.

Upvotes: 1

Related Questions