Coding for the Constructor of the StudentFrame Class – Querying Data from Databases

6.3.9.3   Coding for the Constructor of the StudentFrame Class

Now open our new project, OracleSelectStudent, and the Code Window of the StudentFrame class, and enter the code shown in Figure 6.51 in the top of this window and the constructor of this class. Let’s have a closer look at this piece of code to see how it works.

  1. Ten useful Java packages are added first, since we need to utilize some classes defined in these packages. The first package, java.sql.*, provides all classes and interfaces used in JDBC API for SQL Server expressions. The next two packages contain all related classes and interfaces used for the CachedRowSet component and CachedRowSet Implementation

FIGURE 6.51   The code for the constructor of the StudentFrame class.

classes. As we mentioned, the CachedRowSet is an abstract class, and we have to use its implementation class to perform any data query.

B. One class-level variable is declared here, since we need to use it in our whole class. The variable msgDlg is used to track and display any debug and warning information if any error is encountered during our project’s run.

C. The query method is added into the Query Method combo box. In this application, we only use one method, CachedRowSet Method.

D. Five students’ names are added into the Student Name combo box.

Next let’s Figure out the code for the Select button Click event handler. When this button is clicked, detailed information about the selected student should be displayed in both the seven text fields and the Course Selected Listbox.

Leave a Reply

Your email address will not be published. Required fields are marked *


© 2024 vogafloat, LLC ,About, Careers, Contact us,Cookies, Terms, Privacy