【发布时间】:2014-01-25 14:52:44
【问题描述】:
是否可以在更新查询中插入来自字段?
我需要它,因为在更新某些东西之前,我需要做一些控制。
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
+ "'");
【问题讨论】:
-
如果您知道应该使用准备好的语句,为什么不这样做呢?在准备好的声明中,无论如何您都不会得到所有这些引号,因此问题可能会消失。请注意,您提供给我们的代码不是有效的 Java...
-
我以为我可以从查询中进行更新,但我错了,无论如何我意识到准备好的语句更容易编写并且更受保护