Using a Generic Database Bean
All the
database custom action
tag handler classes described later in this chapter are based on a
generic database bean named
com.ora.jsp.sql.SQLCommandBean
. This bean uses a number of other
classes. Figure 17.3 shows the relationship between
all these classes.
Figure 17-3. The SQLCommandBean and related classes
The SQLCommandBean
takes care of setting all
values in a JDBC
java.sql.PreparedStatement
and executing the statement. For
SELECT
statements, it also processes the result by
creating com.ora.jsp.sql.Row
objects containing a
com.ora.jsp.sql.Column
object for each column in
the result. The rows returned by the SELECT
statement are returned to the caller as a
java.util.Vector
with Row
objects.
The EmployeeRegistryBean
described in Chapter 15 is one example of how to use this bean, and
other examples follow in this chapter. Let’s look at each class
in detail, starting with the SQLCommandBean
itself.
The SQLCommandBean and Value Classes
The SQLCommandBean
has three write-only properties. Example 17.3 shows
the beginning of the class file with the setter methods.
Example 17-3. SQLCommandBean Property Setter Methods
package com.ora.jsp.sql; import java.util.*; import java.sql.*; import com.ora.jsp.sql.value.*; public class SQLCommandBean { private Connection conn; private String sqlValue; private Vector values; private boolean isExceptionThrown = false; ...
Get Java Server Pages now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.