9.14.4.4 Create and Build the Web Operation InsertCourse()
One issue to be noted to perform the new course insert action against our sample database is that we need to perform two queries for this operation, 1) query the Faculty Table to get the desired fac-ulty _ id based on the input faculty _ name, and 2) insert a new course record based on the queried faculty _ id from 1). The reason for that is because there is no faculty _ name col-umn available in the Course Table, and the only connection between the Faculty and the Course Table in our sample database is a foreign key, faculty _ id, defined in the Course Table

FIGURE 9.80 The completed Add Operation wizard.
Keep this fact in mind, and let’s start to build this operation. First perform the following opera-tions to add a new operation, InsertCourse(), into our Web service project:
1) Double-click on our Web service main class file, WebServiceCourse.java, from the Projects window to open it.
2) Click the Design button at the top of the window to open the Design View of that class.
3) Click on the Add Operation button to open the Add Operation wizard.
4) Enter InsertCourse into the Name field and click on the Browse button that is next to the Return Type combo box. Type boolean into the Type Name field and select the item Boolean (java.lang) from the list, and click on the OK button.
5) Click on the Add button and enter cdata into the Name parameter field. Then click on the dropdown arrow of the Type combo box and select the Choose item to open the Find Type wizard. Type ArrayList into the top field and select the ArrayList (java.util) data type, and click on the OK button to select an ArrayList as the data type for the input parameter.
Your finished Add Operation wizard should match the one shown in Figure 9.80. Click on the OK button to save this operation. Next let’s build the code for this operation.
Click on the Source button on the top of this window to open the code window of our Web service class file, and enter the code shown in Figure 9.81 into this new added operation InsertCourse(). Let’s have a closer look at this piece of new added code to see how it works.
A. One Java package with two classes, java.util.logging.Level and java.util. logging.Logger, is imported first at the top of this code window since we need them to find or create our logger file if any exception occurs later.
B. Some local variables, such as an instance of ResultSet, rs; a blank faculty _ id string, fid; and an integer variable, numInsert, are declared since we need to use them to hold some of our query results.
C. A try-catch block is used to do our first query for the Faculty Table to get a desired faculty _ id based on the selected faculty _ name. First a valid database connec-tion is established by calling our user-defined method, DBConnection().

FIGURE 9.81 The detailed code for the operation InsertCourse().