G. The query is then executed by calling the execute() method to perform the first query using the CachedRowSet instance.
H. A while() loop is used to repeatedly pick up all seven pieces of information related to the selected student. The next() method works as the loop condition, and it returns a true as long as a valid row can be found from the returned data by the execution of the CachedRowSet object. The result of running thenext() method is to move the cursor from the initial position to the first row in the returned data stored in the RowSet. In fact, only one row is returned and stored in the CachedRowSet object for the first query, and a sequence of getXXX() methods is used to pick up each column from the RowSet and assign each of them to the associated text field to be display on the StudentFrame Form.
I. To execute the second query, the setCommand() method is called again to create an execuTable Command object with the second query string as the argument. Then the set-String() method is called to set up the positional parameter, student _ id, for the second query statement. The actual value for this parameter can be obtained from the Student ID text field, and it is retrieved and filled by the first query.
J. The query is executed by calling the execute() method to perform the second query using the CachedRowSet instance.
K. In order to pick up the second query result, which contains multiple rows with one column, we need to declare a local integer variable, index, and a String array, Result[], and initialize them. This step is necessary; otherwise, a NullPointer exception may be encountered if this array has not been initialized when the project runs later.
L. A while() loop is used with the next() method as the loop condition. Each time the next() method is executed, the cursor in the CachedRowSet object is moved down one step to point to the next returned row. The getString() method is used to pick up that row and assign it to the local String variable, sResult, and, furthermore, to the String array Result[]. The input number used in the getString() method indicates the cur-rent column’s number (only one column is collected), and this process will be continued until all rows have been collected and assigned to the Result[] array.
M. All courses, that is, all course _ id values, are collected and stored in the Result[] array and assigned to the Course Selected Listbox to be displayed in there. The setList-Data() method is a very useful method, and the argument of this method must be an array when this method is executed.
N. The CachedRowSet object must be closed when it has finished its mission. A close() method is used to perform this job.
O. To retrieve the student’s image, we still need to use the ResultSet object, since the CachedRowSet cannot get any Blob from a database; it only can retrieve an Object via the getObject() method. An issue is that this Object data type cannot be converted to a Blob type, so we cannot use the CachedRowSet to directly get a Blob. For that purpose, a ResultSet object, rs, is generated, and the first query is executed again to pick up all eight pieces of a student’s information.
P. A while() loop is executed to pick up the selected student’s image and assign it to our local Blob variable, simgBlob, which will be used later by the ShowStudent() method.
Q. The catch block is used to collect any possible exception and display it if it did occur. R. Another try-catch block is used to call our user-defined method, ShowStudent(),whose code will be built later, to display the selected student’s image in the Canvas in our StudentFrame Form.
S. Another catch block is used to collect any possible exceptions and display them if they did occur.
Next let’s build a user-defined method to display a student picture for the selected student.