Let’s have a closer look at this piece of modified code to see how it works.

A. First, we add an if block to distinguish between the Java UpdaTable ResultSet method and other query methods to perform this data insertion.

B. An else if block is added with the same objective as step A.

C. The query string is created, and it is used to help the UpdaTable ResultSet object do the data insertion action. One point to be noted is that because of a limitation of the UpdaTable ResultSet under JDBC 4.0, you cannot use a star () following the SELECT to query all col-umns from the target Table; instead, you have to explicitly list all columns for this query. An option is to use Table aliases, such as SELECT f. FROM Table f . . . to do this kind of query.

D. A try-catch block is used to perform the data insertion. A PreparedStatement is created with two ResultSet parameters, TYPE _ SCROLL _ SENSITIVE and CONCUR _ UPDATable, to define the ResultSet object to enable it to be scrollable and updaTable and to perform data manipulation.

E. The setString() method is used to initialize the positional parameter in the query string.

F. The executeQuery() method is called to perform this query and return the query result to a new created ResultSet object.

G. In order to insert a new row into the ResultSet, the moveToInsertRow() method is exe-cuted to move the cursor of the ResultSet to a blank row that is not a part of the ResultSet but is related to the ResultSet.

H. A sequence of updateString() methods is executed to insert the desired columns into the associated columns in the ResultSet. The point to be noted is that different upda-teXXX() methods should be used if the target columns have different data types, and the XXX indicates the associated data type, such as Int, Float or Double.

FIGURE 7.16   The modified code for the constructor of the FacultyFrame class.

FIGURE 7.17   The modified code for the Insert button click event handler.