17Writing CFX Tags with Java
Table 30.12 (continued)
ACTION DESCRIPTION COLUMNS RETURNED
GetProcedureColumns PROCEDURE_NAME, COLUMN_NAME,
COLUMN_TYPE
GetPrimaryKeys A description of primary keys. TABLE_NAME, COLUMN_NAME,
KEY_SEQ
GetIndexInfo ASC_OR_DESC
, COLUMN_NAME,
TABLE_NAME, INDEX_NAME,
NON_UNIQUE, TYPE
NOTE
You can get more specific information about the columns returned by each action by looking through the Java SDK documentation
for the
java.sql.DatabaseMetaData interface.
Writing the Java Code
The <CFX_DatabaseMetaData> tag will use a number of classes and methods from the java.sql pack-
age, which are standard, built-in classes supported by the Java 2 SDK and JRE. It’s not possible for
me to explain everything about these classes in these pages, but here is a quick introduction to the
most important classes used in the next example listing:
■
java.sql.DriverManager. This static class is used to obtain connections to data sources.
Its most important method is
getConnection(), which connects to a database based on a
set of connection arguments (the name and location of the database and so on). Before
the
getConnection() method is called, it is traditional to load a database driver using
Class.forName() (see the Java SDK documentation for details).
■
java.sql.Connection. This class is returned by getConnection() and represents an active
connection to a database. In this example, we will be most interested in its
getMetaData()
method, which returns a DatabaseMetaData object (discussed next).
■
java.sql.DatabaseMetaData. This is the class that the CFX tag is most interested in using.
The various actions supported by the tag (see Table 30.12) map directly to many of this
class’s methods, such as getTables() and getColumns(). These methods all return ResultSet
objects containing the requested information.
■
java.sql.ResultSet. This class is the Java equivalent to a ColdFusion query recordset.
Within the CFX tag, the
ResultSet object returned by DatabaseMetaData is converted to
a ColdFusion query using the methods outlined in Table 30.6.
■
java.sql.ResultSetMetaData. This class is conceptually similar to DatabaseMetaData in
that it returns metadata (column names, data types, and so on), but is smaller in scope
and only returns metadata about a particular
ResultSet, rather than the database as a
whole. This CFX tag uses this class to get the names of the columns in the
ResultSet
returned by DatabaseMetaData.
A description of the indexes in the
database.
A listing of columns returned by
stored procedures. Also includes
information about the procedure’s
input and output parameters.
Comentários a estes Manuais