Я хочу удалить строку из моей базы данных, но она не работает. У меня есть 2 исключения:
- NumberFormatException: null (это для части parseInt в сервлете)
- PSQLException: ОШИБКА: отношение "пациенты" не существует ... но оно существует!
Можете ли вы помочь мне решить мою проблему?
DB.java (только метод)
public int deletePatient(int patID) {
try {
if (conn != null) {
String delete = "DELETE FROM \"Patients\" WHERE Patients.PatientID = ?";
PreparedStatement pstmt = conn.prepareStatement(delete);
pstmt.setInt(1, patID);
affectedRows = pstmt.executeUpdate();
} else {
System.out.println("Connection is not created! 5");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return affectedRows;
}
return affectedRows;
}
ServletP.java (только метод)
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, NumberFormatException {
try {
int patID = Integer.parseInt(request.getParameter("patID2"));
db.deletePatient(patID);
} catch (NumberFormatException n) {
n.printStackTrace();
}
PrintWriter writer = response.getWriter();
String htmlRespone = "<html>";
htmlRespone += "<h2>Action is done!</h2>";
htmlRespone += "<a href=\"/WebApp/patients\">Back</a>";
htmlRespone += "</html>";
writer.println(htmlRespone);
}
JSP:
<div>
<form method="POST" action="patients">
<table border="2" align="center">
<tr>
<td>ID:</td>
<td><input type="text" name="patID2"></td>
<td><input type="submit" value="Delete"></td>
</tr>
</table>
</form>
</div>