Calling the Stored Procedure from the Application

The steps in this section modify the insert_action.jsp file, which processes the form on the insert.jsp page, to use the radio button selection and select the appropriate method for inserting a new employee record.

  1. Open insert_action.jsp in the Visual Editor, if it is not already open.
  2. Double-click the scriptlet to invoke the Scriptlet Properties dialog box and add a new variable after the salary variable, as follows:
    String useSPFlag = request.getParameter("useSP");
    
  3. Below that, still in the Scriptlet Properties dialog box, replace the existing empsbean.addEmployee line with the following lines of code to select the addEmployeeSP method or the pure JDBC addEmployee method to insert the record.
    if ( useSPFlag.equalsIgnoreCase("true"))
      empsbean.addEmployeeSP(first_name, last_name, email, 
      phone_number, job_id, salary.intValue()); 
    // otherwise use pure JDBC insert
    else
      empsbean.addEmployee(first_name, last_name, email, 
      phone_number, job_id, salary.intValue()); 
    
  4. Save insert_action.jsp.

You can now run the application and use the radio buttons on the insert page to choose how you want to insert the new employee record. In a browser, the page will appear as shown in Figure 6-2.

Figure 6-2 Using Stored Procedures to Enter Records

Description of Figure 6-2 follows
Description of "Figure 6-2 Using Stored Procedures to Enter Records"