SQL 插入条件异常的查询

SQL Insert Query With Condition Exception

我有这个查询:

 String requete = "INSERT INTO reduction(newPrix) VALUES (?) "
                        + "WHERE id_prom=? AND id_prod=?";

我遇到异常:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id_prom=2 AND id_prod=6' at line 1

我想知道为什么 INSERT 查询失败了。任何建议表示赞赏。

您在 table 中插入一行。 这意味着您需要指定所有强制值(即不可为空且没有默认值的列的值)。 您不能在这种插入语句中使用 where 子句。这意味着什么?在您的程序中,您可以验证要添加到 table 中的数据的有效性,并决定是否插入。