简体   繁体   English

DELETE查询未从数据库表中删除

[英]DELETE query not deleting from database table

I'm new to JSP and I'm trying to create a web interface where a user can enter information that they want to deleted and it will delete in the database table. 我是JSP的新手,正在尝试创建一个Web界面,用户可以在其中输入要删除的信息,该信息将在数据库表中删除。

Here they should enter the student_id and the course_id , and then any data that have the 2 specified id's should be deleted. 在这里,他们应该输入student_idcourse_id ,然后删除所有具有2个指定ID的数据。 however, it is not deleting from the table. 但是,它不是从表中删除。 I'm getting an exception 我要例外了

array index out of bounds 数组索引超出范围

Here is my code: 这是我的代码:

Delete Row where Student ID: <input type="text" name="dStudent">
and Course ID: <input type="text" name="dCourse">
<input type ="submit" value="Delete">

String delCourse = request.getParameter("dCourse");
String delStudent = request.getParameter("dStudent");

if(delCourse != null && delCourse.length() > 0 && delStudent != null && delCourse.length() > 0){
    statement.executeUpdate("DELETE FROM enroll WHERE student_id = '" + Integer.parseInt(delStudent) + "' AND course_id = '" + Integer.parseInt(delCourse));
}

You're not closing the single quote after Integer.parseInt(delCourse), that could be an issue. 您没有在Integer.parseInt(delCourse)之后关闭单引号,这可能是一个问题。 Of course, to be a lot safer you should use a PreparedStatement ( http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html ) and pass integer values via setInt. 当然,为了更加安全,您应该使用PreparedStatement( http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html )并通过setInt传递整数值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM