I have an Employee management application that can perform operations on tables in the database. My problem is when i try to delete a parent record (department record) it doesn't delete it because the department has employees in it , but it doesn't also notify the user . i want a way to handle this , a popup message or print exception description on the screen , something like that.
it maybe an easy problem but am new to programming , can you please help .
Thanks in advance this is the deleteMethod from DepartmentDao.java :
public void deleteDepartment(int deptno) {
try {
PreparedStatement preparedStatement = connection.prepareStatement("delete from dept where deptno=?");
preparedStatement.setInt(1, deptno);
preparedStatement.executeUpdate();
} catch (SQLException e) {
}// catch
} // deleteDepartment
this is the DepartmentController.java :
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward = "";
String action = request.getParameter("action");
if (action.equalsIgnoreCase("insert")) {
forward = ADD_DEPARTMENT;
} else if (action.equalsIgnoreCase("delete")) {
int deptNo = Integer.parseInt(request.getParameter("deptno").trim());
deptDao.deleteDepartment(deptNo);
forward = DEPARTMENTS;
here's the DepartmentUpdate.jsp
<!DOCTYPE html>
<%@ page contentType="text/html;charset=windows-1256"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256"/>
<link rel="stylesheet" type="text/css" href="resources/css/styles.css" />
</head>
<body>
<form method="POST" action='departmentcontroller' name="frmAddUser">
<input type="hidden" name="theAction" value="update">
<table align="center">
<tr><th colspan="2">Update Department</th></tr>
<tr><td>Department Number : </td><td><input type="text" name ="deptno" value="<%=request.getAttribute("deptno")%>" disabled="disabled"></td></tr>
<tr><td>Department Name</td><td><input type="text" name="dname" value="<%=request.getAttribute("dname")%>"></td></tr>
<tr><td>Location</td><td><input type="text" name="loc"></td></tr>
<tr><td colspan="2"> <input type="submit" name="updateDepartment" value="Update"></td></tr>
</table>
</form>
</body>
</html>