6.3.9.4 Coding for the Select Button Event Handler to Query Data Using the CachedRowSet
Open this event handler and enter the code shown in Figure 6.52 into this handler. Let’s have a closer look at this new added piece of code to see how it works.
- Two local objects, simgBlob and rowSet, are declared first; the first one is used to hold the retrieved student image, and the second is used to create a CachedRowSet object.
- Then a new CachedRowSet object is created with the RowSetFactory class, newFactory(), which is created by a RowSetProvider. One point to be noted is that the old syntax used to create this CachedRowSet object, CachedRowSet rowSet = new Cached RowSetImpl();, is no longer available after JDBC 9.0. A try-catch block is used for this creation.
C. As we know, there is no student _ name column available in the StudentCourse Table, and the only relationship between a student and a course taken by that student is the student _ id, which is a primary key in the Student Table but a foreign key in the

FIGURE 6.52 The code for the Select button Click event handler.
StudentCourse Table. In order to pick up all courses taken by the selected student, we need to perform two queries; first, we need to perform a query to the Student Table to get a student _ id based on the selected student _ name, and then we can perform another query to the StudentCourse Table based on the student _ id to get all courses taken by the selected student. The first query string, strStudent, is created here with a positional parameter, student _ name.
D. The second query string, strStudentCourse, is also created, with another positional parameter, student _ id.
E. If the user selectsthe CachedRowSet Method, a try-catch block is used to perform this query using the CachedRowSet implementation component. First, a database connection with param-eters, such as url, username and password, isset up since we are using a direct implemen-tation with a direct connection to our sample database. The setCommand() method is used to create an execuTable command with the first query string, strStudent, as the argument.
F. The setString() method is used to set up the real value for the positional parameter, student _ name, which is obtained from the Student Name combo box, ComboName.