我正在编码
String Name = txtName.getText();
String Surname = txtSurname.getText();
st.executeUpdate("DELETE from list WHERE Name=@Name and Surname=@Surname");
但它不会删除记录。语法有问题吗?请帮忙。
答案 0 :(得分:2)
您需要将@name
和@surname
替换为实际值。
并在您的值周围添加'
:
DELETE from list WHERE Name='@Name' and Surname='@Surname'
String Name = txtName.getText().Trim();
String Surname = txtSurname.getText().Trim();
String query = "DELETE from list WHERE Name='" + Name + "' and Surname='" + Surname + "'";
st.executeUpdate(query);
答案 1 :(得分:0)
尝试:
st.executeNonQuery("DELETE from list WHERE Name=?e and Surname=?");
并将名称和姓氏作为参数传递。
答案 2 :(得分:0)
使用此
如果表格列表存在。
这会奏效。
String Name = txtName.getText();
String Surname = txtSurname.getText();
st.executeUpdate("DELETE from list WHERE Name='"+Name"' and Surname='"+Surname"'");
我修理了它:
st.executeUpdate("DELETE from list WHERE Name='"+txtName.getText()+"'" + "and Surname='" + txtSurname.getText()+"'");
谢谢大家