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

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

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


E. The setString() method is used to set up the actual value for the positional dynamic parameter in the query statement.

F. The query is performed by calling the executeQuery() method and the query result is returned and stored in a ResultSet object, rs.

G. To get more detailed information about the queried database, the getMetaData() method is executed, and the result is stored in a ResultSetMetaData instance, rsmd.

H. A while() and for() loop are used to pick up all pieces of queried course informa-tion stored in the ResultSet object rs. The for() loop is used to pick up each piece of detailed course information and add it into the ArrayList instance result. One issue to be noted is the upper bound of the loop count for this for() loop. Here we did not col-lect all pieces of detailed course information, since the last column in the Course Table is the faculty _ id, and we do not need this piece of information to be displayed in our Course Form when we consume this service later. Thus, the count for the last column is getColumnCount()—1.

FIGURE 9.79  The test result for our Web Service operation, QueryCourse().

I. A sequence of cleaning jobs is performed to close all used objects.
J. The queried result stored in the local variable result is returned to the calling method.
K. The catch block is used to catch and display any possible error during this query, and a null is returned to indicate this situation if any of errors really occurs.
Now let’s build and test this Web Service operation by using the Web Service Tester.

Click on the Clean and Build Main Project button at the top of the window to build our Web service project. Then right-click on our Web service application project WebAppCourse and choose the Deploy item to deploy our Web service.

If everything is fine, expand the Web Services node under our Web service project and right-click on our Web service target file, WebServiceCourse, and choose the Test Web Service item to run our Web service project. Enter a desired course _ id, such as CSE-432, into the text field and click on the queryCourse button to test the query function. The test result is shown in Figure 9.79.

It can be seen from Figure 9.79 that all six pieces of detailed course information related to the selected course _ id, except the faculty _ id, have been retrieved and displayed at the bot-tom of this page, and our course query via Web service is successful! Close our Web page now.

Next let’s handle creating and building our third Web service operation, InsertCourse(), to insert a new course record into the Course Table in our sample database.

Angela Gaffney

  • 0

Leave a Reply

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


                Copyright © 2024 Saucierlight.com. All Rights Reserved.