2017-05-28 78 views
0

我想从我的“学生”表中删除记录,该表有两列rollno和学生名称。我正在使用PreparedStatement但我收到了一些错误。我无法理解错误。错误是:删除语句中的语法错误

您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,在'?'附近使用正确的语法。在1号线

这里是我的代码

String query = "delete from student where rollno = ?"; 

    PreparedStatement pst = con.prepareStatement(query); 

     pst.setInt(1, 7); 
    pst.executeUpdate(query); 
+2

你忘了分享最重要的部分:你如何执行查询? – BackSlash

回答

3

有可能你所呼叫的执行是这样的:

pst.executeUpdate(query); 

这将执行原始查询,没有你之前设置的参数。

你要改为执行准备好的查询,所以只需使用:

pst.executeUpdate();