【发布时间】:2017-09-24 02:35:27
【问题描述】:
我无法从 SQL 表中删除一行。架构的名称是“imageusers”。在“imageusers”中有一个名为“images”的表,它包含三列:imageID、username 和 image,但我将忽略 image 列,因为我可以删除该行而无需为该信息制作准备好的语句。
我的代码:
myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/imageusers?autoReconnect=true&useSSL=false&relaxAutoCommit=true", "user", "password");
String update = ("DELETE FROM images WHERE imageID = ?, username = ?");
PreparedStatement preparedStatement = myConn.prepareStatement(update);
preparedStatement.setString(1, "image name");
preparedStatement.setString(2, "username");
preparedStatement.executeUpdate();
我已经仔细检查了所有内容。 myConn 连接有效。图像名称和用户名字符串有效且存在于 sql 表中。
但是当我尝试运行它时,我收到以下错误:
"com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你有 SQL 语法错误;检查与您对应的手册 MySQL 服务器版本,用于在 'WHERE imageID = 附近使用正确的语法 '图像名称',用户名 = '用户名'' 在第 1 行。
我在网上看了,这是在 JDBC 中从 sql 中删除一行的正确方法,不是吗?我看到的每个例子都是这样的。我正在运行 MySQL 工作台。
【问题讨论】:
-
您需要在 where 子句中使用 'and' 而不是逗号: Where imageID = ?和用户名 = ?