删除用户选择的记录?

时间:2012-05-07 09:28:37

标签: java mysql

我正在编码

String Name = txtName.getText();
String Surname = txtSurname.getText();  
st.executeUpdate("DELETE from list WHERE Name=@Name and Surname=@Surname");

但它不会删除记录。语法有问题吗?请帮忙。

3 个答案:

答案 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()+"'");

谢谢大家