Blog / The Organization of Web Service Operations – Develop Java Web Services to Access Databases

The Organization of Web Service Operations – Develop Java Web Services to Access Databases

The Organization of Web Service Operations – Develop Java Web Services to Access Databases


9.14.3   The Organization of Web Service Operations

The main purpose of using our Web service is to query and manipulate data from the Course Table in our sample database. Therefore, we need to add some new operations to the Web service project. We will add five new operations based on the sequence of five operational tasks on the Course Table. This means that we will add the following five operations into this Web service project to perform related course information query and manipulation actions:

QueryCourseID():                Query all course_id taught by the selected faculty member.

QueryCourse():                    Query detailed information for the selected course_id.

InsertCourse():                     Insert a new course record into the Course Table.

UpdateCourse():                   Update an existing course record in the Course Table.

DeleteCourse():                     Delete a course record from the Course Table.

Next let’s start to build these five Web operations in our Web Service project one by one. We can combine all operations in one Web Service class file, WebServiceCourse.java.

9.14.4   Create and Build Web Service Operations

Let’s create each Web operation one by one starting from QueryCourseID().

Recall that when we built our sample database in Chapter 2, especially when we built the Course Table, there was no faculty _ name column available in the Course Table, and the only relationship between each course _ id and each faculty member was the faculty _ id column in the Course Table. This is a many-to-one relationship between the course _ id and the faculty _ id in this Table, which means that many courses (course _ id) can be taught by a single faculty member (faculty _ id). However, in the Faculty Table, there is a one-to-one relationship between each faculty _ name and each faculty _ id column. Therefore, in order to query all courses, that is, all course _ id values, taught by the selected faculty member, that is, the faculty _ name, we need to perform two queries from two Tables.

  • First we need to perform a query to the Faculty Table to get a matching faculty _ id based on the selected faculty member (faculty _ name).
  • Then we need to perform another query to the Course Table to get all course _ id values taught by the selected faculty _ id that is obtained from the first query.

In fact, we can combine these two queries into a single JOIN query to simplify this process.

Based on this discussion, now let’s perform the following operations to add a new operation, QueryCourseID(), into our main class file, WebServiceCourse.java, to perform this course _ id query.

Angela Gaffney

  • 0

Leave a Reply

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


                Copyright © 2024 Saucierlight.com. All Rights Reserved.