Closing Open Objects in the Application

You must close the ResultSet, Statement, and Connection objects only after you have finished using them. In the DataHandler class, the insert, update, and delete methods must close these objects before returning. Note that the query methods cannot close these objects until the employees.jsp page has finished processing the rows returned by the query.

In the following steps, you add the appropriate calls to the closeAll method in the DataHandler.java file:

  1. Open DataHandler.java in the Java Source Editor.
  2. At the end of the addEmployee method, after the closing brace of the catch block, add the following call to the closeAll method in a finally block:
    finally {
      closeAll();
    }
    
  3. Add the same call to the addEmployeeSP, deleteEmployeeById, findEmployeeById, updateEmployee, and authenticateUser methods.
  4. Open the employees.jsp file in the Visual Editor. Find the scriptlet inside the Employees table, and double-click to open the Insert Scriptlet dialog box.
  5. Add the following statement after the while loop:
    empsbean.closeAll();
    
  6. Save your work, and compile and run the application to ensure that everything still works correctly.