Blog / Create and Build the Web Operation UpdateCourse() – Develop Java Web Services to Access Databases

Create and Build the Web Operation UpdateCourse() – Develop Java Web Services to Access Databases

Create and Build the Web Operation UpdateCourse() – Develop Java Web Services to Access Databases


9.14.4.5  Create and Build the Web Operation UpdateCourse()


Perform the following operations to add a new operation, UpdateCourse(), into our Web service project to perform a course update query:

1) Double-click on our Web service main class file, WebServiceCourse.java, from the Projects window to open it.
2) Click on the Design button at the top of the window to open the Design View of our Web service class file, WebServiceCourse.java.
3) Click on the Add Operation button to open the Add Operation wizard.
4) Enter UpdateCourse 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, 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.82. Click on the OK button to create this operation. Next let’s build the code for this operation.

FIGURE 9.82  The completed Add Operation wizard.

FIGURE 9.83   Detailed code for the operation UpdateCourse().

As we discussed in the previous chapters, to update a record in the Course Table, usually one does not need to update the primary key, course _ id; instead, one can insert a new course record with a new course _ id into the Course Table to simplify the update. The reason for that is because of cascaded update actions. course _ id is a primary key in the Course Table but a foreign key in the StudentCourse Table. Multiple update actions must be performed in multiple Tables in a certain order if this primary key course _ id is updated. To make thing simple, here we would not update any course _ id when we update a course record, but we only update all other columns in the Course Table based on the original course _ id.

Based on this discussion and analysis, now 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 project. In the opened code window, enter the code shown in Figure 9.83 into the new added operation, UpdateCourse().

Let’s have a closer look at this piece of new added code to see how it works.

Angela Gaffney

  • 0

Leave a Reply

Your email address will not be published. Required fields are marked *


                Copyright © 2024 Saucierlight.com. All Rights Reserved.