Blog / Build the Code to Call the UpdateFaculty() Operation – Develop Java Web Services to Access Databases

Build the Code to Call the UpdateFaculty() Operation – Develop Java Web Services to Access Databases

Build the Code to Call the UpdateFaculty() Operation – Develop Java Web Services to Access Databases


9.12.2   Build the Code to Call the UpdateFaculty() Operation

Open our Window-based client project, WinClientFaculty _ UpdtDelt, and double-click on our main class, FacultyFrame.java, to open it. Click on the Design button to open the graphic user interface. In this client project, we need to use the Update button as a trigger to start the faculty data update action. Therefore double-click on the Update button to open its event method, UpdateButtonActionPerformed(), and enter the code shown in Figure 9.60 into this method.

FIGURE 9.60   The complete code for the UpdateButtonActionPerformed() method.

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

A. Some local objects are first declared, which include a File object, imgFile, which is used to hold the selected image file, and a new ArrayList instance, al, which is used to pick up and reserve the input updated faculty data array.

B. A Java File Chooser instance, imgChooser, is generated, and it provides a file inter-face GUI to allow users to select a desired faculty image to be updated to our database later.

C. The current directory, which is the folder of our current project, is selected, and this loca-tion will work as a default folder to store all selected faculty image files later.

D. The system method, showOpenDialog(), is executed to display the Chooser GUI to enable users to browse and select a desired faculty image to be updated to our database later.

E. By checking one property, APPROVE _ OPTION, one can confirm whether this GUI’s operation is successful. If it is opened and an image has been selected, a true is returned. Then the selected image can be retrieved by calling a method, getSelectedFile().

F. These two code lines are used to display the path and directory for the selected faculty image, and they are used for debugging purposes.

G. The clear() method is executed to make sure that the ArrayList instance is clean before an updated faculty record can be collected.

H. A sequence of add() methods is used to pick up and add eight pieces of updated faculty information into this new ArrayList instance, al. These eight pieces of updated faculty information are entered by the user and stored in seven text fields and the File Chooser in this FacultyFrame window form. The toString() method is used to convert the pieces of faculty information obtained using the getText() method that returns an object data type to a String. The index is necessary since it is used to indicate the position of each parameter in this ArrayList. One point to be noted is the order of adding these text fields, which must be identical to the order of columns in our Faculty Table.
I. A try catch block is used to perform the calling of our Web service operation, UpdateFaculty(), to perform this faculty data update action. First a new Web service instance, service, is created based on our Web service class, WebServiceFaculty _ Service. Then the getWebServiceFacultyPort() method is executed to get the current port used by our Web service. This port is returned and assigned to a new port instance, port.

J. The Web service operation updateFaculty() is executed with the ArrayList instance al that has been filled with eight pieces of updated faculty information as the argument of this method. The run result of that operation is returned and assigned to a Boolean vari-able, update.

K. If the value of the variable update is false, which means that no row has been updated in our Faculty Table and this update action has failed, the msgDlg instance is used to show this situation.

L. Otherwise, if the value of the update variable is true, which means that the data update action is successful, the new updated faculty name will be added into the Faculty Name combo box ComboName using the addItem() method.

M. The catch block is used to track and display any possible exception during this Web service operation execution.

Next let’s build the code to perform the faculty data delete action.

Angela Gaffney

  • 0

Leave a Reply

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


                Copyright © 2024 Saucierlight.com. All Rights Reserved.