MySQL Java语法错误
试图找出此java代码中的错误MySQL Java语法错误,java,mysql,Java,Mysql,试图找出此java代码中的错误 The SQLException reads: " 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 'order (item_quantity, customer_id, product_id) VALUES (5, 191, 31)' 订单
The SQLException reads: " 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 'order (item_quantity, customer_id, product_id) VALUES (5, 191, 31)'
订单表看起来像order_id int pk ai <br>
item_quantity <br>
customer_id int <br>
product_id int <br>
如果您能提供任何帮助,我们将不胜感激,因为您似乎无法解决此问题。请将订单(表名)用反勾号括起来 如下图所示:
INSERT INTO `order` (item_quantity, customer_id, product_id) VALUES...
注意:
例如,反勾号可以帮助您避免意外使用SQL中的保留字名称。以一个名为“where”的表格为例,我同意这是一个愚蠢的表格名称,但是如果你用反勾号将其包装起来,它会很好地工作请你在
顺序
上反勾号好吗?。编写'Order'
而不是Order
。与此特定问题无关,但一旦您开始熟悉这种SQL方法,就应该开始研究PreparedStatements。它们为您提供了更高的安全性(如果您的int
args是字符串,我会立即想到SQL注入攻击)。您能打印SQL
变量并共享结果吗?SQL变量:插入到“订单”(项目数量、客户id、产品id)值(3、211、31)中可能您没有使用backtick。相反,您使用了单引号。
INSERT INTO `order` (item_quantity, customer_id, product_id) VALUES...