基本上,INSERT
语句不能有WHERE
子句。我在想你想要UPDATE
某个记录,例如
UPDATE accounts
SET inventory = 'valueHere'
WHERE userName = 'userHEre' AND password = 'passHere'
INSERT
语句可以有子句的唯一时间WHERE
是当您从语句的结果中插入记录时SELECT
,例如
INSERT INTO tableName (col1, ..., colN)
SELECT col1, ..., colN
FROM table2
// WHERE ..your conditions here..
作为旁注,您当前的编码风格很容易受到SQL Injection
. 考虑使用PreparedStatement
.
基本示例PreparedStatement
String updateString = "UPDATE accounts SET inventory = ? WHERE userName = ? AND password = ?";
PreparedStatement updateStmt = con.prepareStatement(updateString);
updateStmt.setString(1, Inventory.inventory);
updateStmt.setString(2, Frame.username);
updateStmt.setString(3, Frame.password);
updateStmt.executeUpdate();