具有多列的JDBC delete语句

时间:2012-12-01 04:49:47

标签: java sql jdbc

它说如果我把它输入到sql plus中,只是添加了;它完美地运作。我做错了什么?

    Statement statement = connection.createStatement();
    statement.executeUpdate("delete from aplbuk  MODEL = '"+   textField_4.getText()  + "'AND  year = '" + textField_1.getText()  + "' AND Litres = '" + textField_2.getText() 
    + "' AND ENGINE_TYPE = '" + textField_3.getText() + "'");
    statement.close();

1 个答案:

答案 0 :(得分:2)

在您的查询where中的表名aplbuk后,

缺少关键字delete from aplbuk MODEL

将查询更新为:

  statement.executeUpdate("delete from aplbuk  where  MODEL = '"+   
                           textField_4.getText()  + "'AND  year = '" + 
                           textField_1.getText()  + "' AND Litres = '" + 
                           textField_2.getText() + "' AND ENGINE_TYPE = '" + 
                           textField_3.getText() + "'");

如果yearLitres是数字字段,则不要将该值括在单引号中。