这是我正在编写的用于管理PostgreSQL的小型JSP servlet的代码片段,JSP声称它无效。
<% if (request.getParameter("student-id") != null &&
request.getParameter("sname") != null &&
request.getParameter("date-of-birth") != null &&
request.getParameter("email") != null &&
request.getParameter("level") != null) {
String update = "UPDATE students SET name = '" + request.getParameter("sname") + "', " +
"date_of_birth = '" + request.getParameter("date-of-birth") + "', " +
"email = '" + request.getParameter("email") + "', " +
"level = '" + request.getParameter("level") + "' " +
"WHERE student_id = " request.getParameter("student-id");
statement.executeUpdate(update);
} %>
出于某种原因,这引发了一个令人讨厌的错误,抱怨缺少分号:
An error occurred at line: 65 in the jsp file: /students.jsp
Generated servlet error:
Syntax error, insert ";" to complete BlockStatements
第65行是我打开&lt;%
的地方答案 0 :(得分:-1)
在student_id =“在这个地方
之后缺少'+'<% if (request.getParameter("student-id") != null && request.getParameter("sname") != null && request.getParameter("date-of-birth") != null && request.getParameter("email") != null && request.getParameter("level") != null) { String update = "UPDATE students SET name = '" + request.getParameter("sname") + "', " + "date_of_birth = '" + request.getParameter("date-of-birth") + "', " + "email = '" + request.getParameter("email") + "', " + "level = '" + request.getParameter("level") + "' " + "WHERE student_id = "+ request.getParameter("student-id"); statement.executeUpdate(update); } %>
答案 1 :(得分:-2)
在这一行你忘了加号
"WHERE student_id = " request.getParameter("student-id");
我可以建议String.format()
作为构建sql语句的更好,更清晰的方法