7.3.1 Modify the Code Inside the FacultyFrame Constructor
The reason we need to do this modification is that some faculty records in the Faculty Table will be changed after the update action. Thus, we need to update the faculty members in the Faculty Name combobox, ComboName, to enable users to check and validate the related update action based on the updated faculty records. One of the most important updates is the faculty name stored in that combobox.
Open our new project, OracleUpdateFaculty, and the FacultyFrame Form, and enter the code shown in Figure 7.9 into the constructor of this class.
The only modification is to replace original eight code lines, which are used to add eight faculty members into the Faculty Name combobox ComboName, with a new user-defined method, CurrentFaculty(), as shown in step A in Figure 7.9.
FIGURE 7.9 The modified code in the FacultyFrame constructor.
FIGURE 7.10 The detailed code in the user-defined method CurrentFaculty().
The detailed code for this method is shown in Figure 7.10. Let’s have a closer look at the code in this method to see how it works.
A. A local ResultSet object, rs, is declared first, since we need to use this object to hold our queried faculty member result.
B. A try-catch block is used to perform this data query. A database connection is estab-lished via the LogInFrame class, and a new PreparedStatement object, pstmt, is created with a query string to retrieve all faculty names from our Faculty Table.
C. The query is executed by calling the executeQuery() method, and the query result is assigned to our local ResultSet object, rs.
D. Prior to updating all faculty names in the ComboName box, it is cleared to make this update action ready with a system method, removeAllItems().
E. A while() loop is used to repeatedly pick up each faculty name with the next() method. The retrieved faculty name, rs.getString(1), is added into the ComboName box by using a system method, addItem(). Since only one column, faculty _ name, is que-ried from the Faculty Table, the column number is 1.
F. The ResultSet object is closed after this query.
G. A catch block is used to collect and report any possible exceptions during that query.
Now let’s develop the code for the Update button even handler to perform the data update action to the Faculty Table via the FacultyFrame Form in this project.