JAVA RUNTIME OBJECTS METHOD
9.12 BUILD A WINDOWS - BASED WEB CLIENT PROJECT
9.12.3 Build and Run Our Client Project to Update and Delete
Click on the Clean and Build Main Project button to build our client project. If every- thing is fi ne, click on the Run Main Project button to run our client project.
The FacultyFrame form window is displayed. First, let ’ s perform a faculty query action. Select a desired faculty member, such as Ying Bai , from the Faculty Name combo box, and click on the Select button to query the detailed information for this faculty via our Web service WebServiceSQL . The queried result is displayed in seven text fi elds.
Now enter an updating faculty record with six pieces of updated faculty information shown below into six text fi elds, which is shown in Figure 9.61 .
Figure 9.60. The complete codes for the cmdDeleteActionPerformed() method.
private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
try { // Call Web Service Operation
org.ws.sql.WebServiceSQLService service = new org.ws.sql.WebServiceSQLService();
org.ws.sql.WebServiceSQL port = service.getWebServiceSQLPort();
// TODO initialize WS operation arguments here
Boolean delete = port.deleteFaculty(ComboName.getSelectedItem().toString());
if (!delete) {
msgDlg.setMessage("The data deleting is failed!");
msgDlg.setVisible(true);
} }
catch (Exception ex){
System.out.println("exception: " + ex);
} } A B
C
c09.indd 831
c09.indd 831 7/20/2011 11:12:51 AM7/20/2011 11:12:51 AM
www.traintelco.com
Click on the Update button to try to call our Web service operation UpdateFaculty() to update this faculty record in the Faculty table in our sample database.
To confi rm this data updating action, two methods can be used. First, we can open our Faculty table using either the Services window in the NetBeans IDE or the SQL Server 2008 Management Studio to check whether this faculty record has been updated.
To do that using the Services window in the NetBeans IDE, perform the following operations:
1. Open the Services window and expand the Databases node.
2. Right click on our SQL Server database URL: jdbc:sqlserver://localhost\SQL2008 EXPRESS: 5000; databaseName=CSE_DEPT [ybai on dbo] , and select the Connect item to connect to our database.
3. Expand our sample database CSE_DEPT and Tables .
4. Right click on the Faculty table and select the View Data item.
Your opened Faculty table is shown in Figure 9.62 . It can be found that the faculty record with the faculty_id of B78880 , which is located at row 4, and has been highlighted in dark color, has been successfully updated in our database.
The second way to confi rm this data updating, which is simpler, is to use the Select button in this form to perform a query to try to retrieve the updated faculty record.
A second way to check this is to go to the Faculty Name combo box, and you can fi nd that the updated faculty name Susan Bai has been added into this box. Click it to
• Name: Susan Bai • Title: Professor • Offi ce: MTC - 200 • Phone: 750 - 378 - 2000 • College: Duke University • Email: sbai@college.edu
Figure 9.61. Six pieces of updated faculty information.
Figure 9.62. The opened Faculty table in the NetBeans IDE.
select it and click on the Select button. Do not worry about the exception message for the faculty image, since we did not insert any image for this new inserted faculty. Just click on the OK button for that message box and you can fi nd that six pieces of updated faculty information have been retrieved and displayed in this form window. Our data updating is successful!
It is highly recommended to recover this updated faculty record to the original one in our database since we want to keep our database clean. Refer to Table 9.6 to recover this original faculty record. You can recover this record by opening the SQL Server 2008 Management Studio to add it or performing another updating action in this form to recover it.
Next, let ’ s test the faculty record deleting action via our Web service operation
DeleteFaculty() . First, let ’ s perform another updating action to recover the updated faculty member Ying Bai using the data shown in Table 9.6 . Enter these six pieces of original faculty information into those six text fi elds and click on the Update button.
Then keep the faculty member Ying Bai selected in the Faculty Name combo box, and click on the Delete button to try to call our Web service operation DeleteFaculty() to delete this faculty record from our sample database.
To confi rm this data deleting action, two ways can be used. First, you can perform a faculty data query operation by selecting the deleted faculty member Ying Bai from the
Faculty Name combo box, and clicking on the Select button to try to retrieve this faculty record from our database. You can fi nd that the querying faculty record cannot be found from our sample database and cannot be displayed in this form, and this means that our data deleting is successful.
Table 9.6. The original faculty record in the Faculty table
faculty_id faculty_name office phone college title email
B78880 Ying Bai MTC-211 750-378-1148 Florida Atlantic University Associate Professor ybai@college.edu
c09.indd 833
c09.indd 833 7/20/2011 11:12:52 AM7/20/2011 11:12:52 AM
www.traintelco.com
Another way to confi rm this data deleting is to open the Faculty table in our sample database.
A point to be noted is that as you perform reupdating actions, you must perform the both updating actions in a short period of time, which means that you have to perform the second updating within a short period of time after you do the fi rst updating action.
A point to be noted is that as you perform data recovery, the recovery order is very important. It means that you have to fi rst recover the faculty data in the Faculty table, and then the data in other tables, since the Faculty table is a primary table.
To make our sample database clean and neat, it is highly recommended to recover this deleted faculty member and related records in our Faculty, LogIn, Course, and StudentCourse tables. An easy way to do this recovery is to use the Microsoft SQL Server 2008 Management Studio. Refer to deleted records shown in Tables 9.2 – 9.5 in Section 9.11.3 to add or insert them back to the related tables to complete this data recovery.
A complete Windows - based client project WinClientSQL can be found from the folder DBProjects\Chapter 9 that is located at the Wiley ftp site (refer to Figure 1.2 in Chapter 1 ).
Next let ’ s build a Web - based client project to consume our Web service to insert a new faculty record into the Faculty table in our sample database.