H. The catch block is used to detect and display any possible exception during this connec-tion process.
I. The established connection object is returned to the calling method.
J. Our Web operation method, QueryCourseID(), is declared and defined with a selected faculty name as the argument.
K. An ArrayList instance, result, is created, and this variable is an array list instance used to collect and store our query result and return to the consuming project.
L. A Joined query statement that combined the first query to the Faculty Table and the second query to the Course Table is declared with one position parameter, faculty _ name. This definition is a so-called ANSI 92 Standard and used to simplify multiple query statements.
M. Another try-catch block is used to perform this query job. First our user-defined method DBConnection() is called to set up a valid database connection to our sample database.
N. A new PreparedStatement instance, pstmt, is created to perform this query.
O. The setString() method is used to set up the actual value for the positional dynamic parameter in the query statement.
P. The query is performed by calling the executeQuery() method, and the query result is returned and stored in a ResultSet object, rs.
Q. To get more detailed information about the queried database, the getMetaData() method is executed, and the result is stored in a ResultSetMetaData instance, rsmd.
R. A while() and for() loop are used to pick up all queried course _ id stored in the ResultSet object rs. A for loop is used to pick up each queried course _ id and add it into the ArrayList instance result. The reason we used an ArrayList, not a List instance, as the returned object is that the former is a concrete class but the latter is an abstract class, and a runtime exception may be encountered if an abstract class is used as a returned object to the calling method.

FIGURE 9.74 The code for the Web service operation QueryCourseID().
S. A sequence of cleaning jobs is performed to close all used objects.
T. The queried result stored in the local variable result is returned to the calling method.
U. The catch block is used to catch and display any possible error during this query.

FIGURE 9.75 The testing status of our Web Service project.
During the coding process, you may encounter some runtime compiling errors. The main reason for those errors is that some packages are missing. To fix these errors, just right-click on any space inside this code window, and select the Fix Imports item to add those missingpackages.
At this point, we have finished all code for the course _ id query. Now let’s build and test our Web service to test the course _ id query function.