8.1.3 Using Java Help Class Files for Java Web Applications
To distinguish between database-related data processing and display of run results, we can separate a Java Web application into two parts: JDBC-related database processing and business logic, such as checking and confirming a username and password pair located in a Java help class file, and the data and run results displayed in a Web or JavaServer page.
Take a look at the code in Figure 8.6, and you can see that about 80% of this code is JDBC-related database processing code, and 10% is data-processing code. In all, about 90% of the code is used to access the database, query for the data and perform data-matching functions. Only about 10% is HTML code.
To separate these two kinds of code into two different files, we can pick up all JDBC-related code and put it in a Java help class file, LogInQuery.java, as shown in Figure 8.7.
Let’s have a closer look at this piece of code to see how it works.
A. Some member data or attributes are defined first inside this class, which includes two private String member data variables, user _ name and pass _ word; a class-level connection variable, con; and a dialog box that is used to display debug information.
B. Inside the class constructor, an Oracle JDBC database driver is loaded, and itis a type IV JDBC driver.
C. The Oracle JDBC URL is assigned to the local variable url.
D. The getConnection() method is executed to establish the database connection.
E. The Java help method checkLogIn() is declared inside the help class. This method is a main function to perform JDBC-related data query and data matching operations.
F. Some local variables used in this method are defined first, which include the Statement and ResultSet objects.
G. A query string is created, and it is used to query a matching username and password from the LogIn Table.
H. The createStatement() method is called to create a Statement object.

FIGURE 8.7 The code for the Java Web help class LogInQuery.java.