Before we can build and run this project to test the functionality of the CallableStatement interface, we need to do one more thing, which is to develop code for the event handler CourseListValueChanged() to display detailed information for each selected course _ id from the Course ID List box.
Open the Design View of the CourseFrame Form window by clicking on the Design tab at the top of the window, and then right-click on the Course ID List box and select the item Events|Li stSelection|valueChanged to open this event handler. Enter the code shown in Figure 6.48 into this event handler.
Let’s have a closer look at this piece of code to see how it works.
- A text field array, c _ field, is created here, since we need to assign the queried detailed course information to six text fields to display it; therefore, it is easy to use an array to do that assignment.

FIGURE 6.48 The code for the CourseListValueChanged() event handler.
B. Since the JList component belongs to the javax.swing package, not the java. awt package, any click on an entry in the CourseList box causes the itemStat-eChanged() method to fire twice, once when the mouse button is pressed, and once again when it is released.
Therefore, the selected course _ id will appear twice when it is selected. To prevent this from occurring, the getValueIsAdjusting() method is used to make sure that no item is allowed to be displayed twice. Then the selected course _ id is assigned to a local String variable, courseid, by calling the getSelectedValue() method of the CourseList Box class.
C. Before we can proceed to the query operation, first we need to confirm that the selected courseid is not a null value. A null value would be returned if the user did not select any course _ id from the CourseList box, that is, if the user just clicked on the Select button to try to find all course _ id values taught by other faculty members. Even if the user only clicked on the Select button without entering any course _ id in the CourseList box, the system still considers that a null course _ id has been selected, and thus a null value will be returned. To avoid that situation, an if selection structure is used to make sure that no null value has been returned from the CourseList box. The course query string is created if no null value has been returned.
D. A try-catch block is used to perform the PreparedStatement query operation. First, a PreparedStatement object is created with the query string as the argument.
E. The setString() method is executed to use the real query criterion, courseid, to replace the nominal position parameter.
F. The dynamic query is actually executed by calling the executeQuery() method, and the query result is returned and stored in a ResultSet object.
G. The getMetaData() method is called to return the detailed information about the returned ResultSet object, including the column number, column name and data type.

FIGURE 6.49 The code for the Back button Click event handler.

FIGURE 6.50 The run result of the CourseFrame Form window.
H. while() and for() loops are used to retrieve the queried columns from the ResultSet object and assign them one by one to the associated Text Field to display them.
I. The catch block is used to track the run status of this piece of code. An error message will be displayed if any exception occurs.
The final coding process is to build the code for the Back button event handler. The function of this event handler is to close the current CourseFrame Form window and direct control back to the SelectFrame Form window to enable users to select a desired item to perform another data query action. Open that event handler and enter the code shown in Figure 6.49 into it.
Now we can build and run our project to test its function. As the project runs, enter an appro-priate username and password, such as jhenry and test, to the LogInFrame Form to finish the login process. Then select the Course Information from the SelectionFrame Form to open the CourseFrame Form window, as shown in Figure 6.50.
Select a desired faculty member, such as Ying Bai, from the Faculty Name combo box, and click on the Select button to try to retrieve all courses (course _ id) taught by that faculty mem-ber. All four courses (course _ id) are fetched and displayed in the CourseList box. Click on any course _ id from that CourseList box, and the details for that course are displayed in six TextFields on the right, as shown in Figure 6.50.
One can try to select other faculty members to do the related data query to test the function of this Form window. Click on the Back and Exit buttons to terminate our project when you are done. A completed project, OracleSelectCourse, can be found in the folder Class DB Projects\Chapter 6 in the Students folder on the CRC Press ftp site (refer to Figure 1.2 in Chapter 1).
Next we’ll discuss how to perform data queries to our Student Table via the Java RowSet method.