6.3.7 Perform a Data Query for the Faculty Table
The function of this frame form is: when the user selects a faculty member from the ComboName combo box and clicks the Select button, detailed information with an image of the selected

FIGURE 6.22 Initialization code for the FacultyFrame class.
faculty member should be displayed in seven text fields and a canvas. The code development of this query can be divided into the following six parts:
1) Add the necessary Java packages and code for the constructor of the FacultyFrame class to perform the initialization processes.
2) Build code for the Select button Click event handler to run the executeQuery() method to query data from the Faculty Table in our sample database using the
DatabaseMetaData interface and ResultSetMetaData interface.
3) Code the Select button Click event handler to run the execute() method to query data from our Faculty Table in our sample database.
4) Code the Select button Click event handler to run the Java Callable method to query data from our Faculty Table in our sample database.
5) Add a user-defined method, ShowFaculty(), to display an image for the selected faculty member in the FacultyFrame Form window.
6) Code the Back button Click event handler to close the FacultyFrame Form window and return control to the SelectionFrame Form.
Steps 2, 3 and 4 include using three different methods to perform this query. Now let’s start with the first part.
6.3.7.1 Add Java Package and Code for the Constructor
Since we need to display an image for the selected faculty member when a data query is executed, the java.awt.* package should be imported, since some image-related classes, such as Image, Graphics and MediaTracker, are located in this package.
Open the Code Window of the FacultyFrame class by clicking on the Source tab at the top of the window and add the code shown in Figure 6.22 into this source file.
Let’s have a closer look at this piece of code to see how it works.
A. Some useful java packages, including two important packages, java.awt.* and java. sql.*, are imported at the beginning of this file, since we need to use some classes defined in those packages.
B. A JDialog object, msgDlg, is created here as a class-level object because we need to use it in the whole class of the FacultyFrame to display debug or warning messages.
C. The addItem() method is used to add all three query methods into the Query Method combo box.
D. Also, the addItem() method is utilized to add all eight faculty members into the
Faculty Name combo box.
Now let’s first have a quick look at some popular JDBC MetaData Interfaces, since we need to use some of them in this faculty query operation.