15Writing CFX Tags with Java
Yo u can even catch exceptions thrown by a CFX and handle them intelligently, using <cftry> and
<cfcatch>, like so:
<cftry>
<CFX_HelloWorld
NAME=”#SESSION.FirstName#”
AGE=”#FORM.Age#”>
<cfcatch type=”Any”>
...error handling code goes here...
</cfcatch>
</cftry>
Returning Query Objects
Now that you’ve seen how to create a simple CFX tag with Java, it’s time to move on to something a
bit more complicated and useful. Our next project will be a CFX tag called
<CFX_DatabaseMetaData>,
which can be used to inspect the structure of a database on the fly. To use the tag in a ColdFusion
page, you will specify the type of information you want (a list of tables, columns, indexes, or the
like), and the tag will return a query object filled with items like column names, table names, data
types, and so on.
Table 30.11 shows the syntax that will be supported by the completed tag.
Table 30.11 <CFX_DatabaseMetaData> Tag Syntax
ATTRIBUTE DESCRIPTION
action Required. A string indicating the type of information you are interested
in, such as
GetTables or GetColumns. You can provide any of the
actions listed in Table 30.12.
driver Required. The name of the JDBC driver to use. For ODBC databases,
you can use Sun’s ODBC Bridge driver, as in
driver=”sun.jdbc.odbc.
JdbcOdbcDriver.”
connect
Required. Whatever connection information the driver needs to connect
to the database. In the case of ODBC datasources, you can use a string
in the form
jdbc:odbc:dsn_name, as in connect=”jdbc:odbc:ows”
for the Orange Whip Studios example database.
username Required. The username for the data source (may be case sensitive).
password Required. The password for the data source (may be case sensitive).
name Required. Like the name attribute for <cfquery>, a name for the query
object that the tag returns. The returned query will contain different
columns depending on the
action you choose, as listed in Table 30.12.
dbcatalog Optional. The catalog name that you want to get information about.
With most database systems, the catalog name is the name or filename of
the database. If you don’t specify a catalog name, all information is
returned (for all available catalogs or databases). Can be used for all
actions except
GetCatalogs and GetSchemas.
Commentaires sur ces manuels