我无法从SQL中的表中删除行。模式的名称是'imageusers'。 'imageusers'里面有一张名为'images'的表格,它有三列:imageID,用户名和图片,但我会忽略图片列,因为我可以删除该行而无需为该人的信息做好准备。在从SQL中的表中删除行时遇到问题
我的代码:
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: 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 'WHERE imageID = 'image name', username = 'username'' at line 1.
我在网上看了看,这是为了在JDBC SQL删除行正确的方法是不是?我看到的每个例子都是这样的。我正在运行MySQL Workbench。
您需要使用“和”,而不是在where子句中使用逗号:如果图像标识=?和用户名=? – user2023608