是否可以在更新查询中插入from字段?
我需要它,因为在更新之前,我需要做一些控制。
p.s我知道我必须使用预备语句,但我想知道这个错误,我想这是一个缺少的引用,我看不到。
错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from warehouse,product where warehouse.idProduct=shop.idProduct and warehouse.id' at line 1
int rs = st.executeUpdate("UPDATE shop SET quantity='"
+ Quantity
+ "' from warehouse,product where
warehouse.idProduct=shop.idProduct and
warehouse.idProduct=product.id and product.brand='"
+ Brand + "' and product.productType='" + Product
+ "'");
答案 0 :(得分:1)
这只是无效的SQL。 UPDATE
语句不能包含FROM
子句。
Single-table syntax:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
Multiple-table syntax:
UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
答案 1 :(得分:0)
我认为你想要一个加入更新:
UPDATE shop s join
warehouse w
on w.idProduct = s.idProduct join
product p
on w.idProduct = p.id and
p.productType = '"+Product+"' and
p.brand = '" + Brand + "'
SET s.quantity = "+ Quantity
作为一个说明。我猜Quantity
是数字。如果是这样,您不需要围绕该值的引号。