关于在SQL中删除带双引号和预处理语句的行的问题
Questions about delete a row with double quotes and prepared statement in SQL
我尝试删除 SQL 中具有相同 bookID
和 userID
的行,但是因为我的 bookID
保存时使用了双引号,所以正常删除不会成功'匹配。我应该怎么办?谢谢。
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND bookID=?;";
try {
conn = DriverManager.getConnection("someLink");
ps = conn.prepareStatement(deleteString);
ps.setInt(1, userID);
ps.setString(2, bookID);
int r = ps.executeUpdate();
}//try
...
here is my sql table
您可以 trim 您的 bookID
以便它匹配您的参数。
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND trim(both '\"' from bookID)=?;";
或
您可以 concat
"
您的参数以匹配您的 bookID
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND bookID=concat('\"', ?, '\"');";
我尝试删除 SQL 中具有相同 bookID
和 userID
的行,但是因为我的 bookID
保存时使用了双引号,所以正常删除不会成功'匹配。我应该怎么办?谢谢。
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND bookID=?;";
try {
conn = DriverManager.getConnection("someLink");
ps = conn.prepareStatement(deleteString);
ps.setInt(1, userID);
ps.setString(2, bookID);
int r = ps.executeUpdate();
}//try
...
here is my sql table
您可以 trim 您的 bookID
以便它匹配您的参数。
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND trim(both '\"' from bookID)=?;";
或
您可以 concat
"
您的参数以匹配您的 bookID
String deleteString = "DELETE FROM booksFavourite WHERE userID=? AND bookID=concat('\"', ?, '\"');";