20.22. Querying a Database with Server-Side ActionScript
Problem
You want to use Server-Side ActionScript (SSAS) to query a database.
Solution
Make sure the database is
registered as a datasource with ColdFusion
or JRun, and then use the query( ) method of the
SSAS CF object.
Discussion
Server-Side ActionScript allows you to query any registered
datasource by way of the CF.query( ) method. The
first step is to make sure that your
database has been properly registered with ColdFusion or JRun. If you
are not sure how to do this, then you should consult your ColdFusion
or JRun documentation.
The CF.query( ) method allows you to pass it the
following arguments as either positional or named parameters:
-
datasource The name of the datasource as registered with ColdFusion or JRun.
-
sql The SQL command.
-
username If the datasource requires a username, you can specify it with this parameter.
-
password If the datasource requires a password, you can specify it with this parameter.
-
maxrows You can optionally specify the maximum number of records to return.
-
timeout An optional number of milliseconds to wait before timing out.
When you use the CF.query( ) method with
positional parameters, you can specify one or more optional
parameters in the following orders:
CF.query(datasource, sql); CF.query(datasource, sql, maxrows); CF.query(datasource, sql, username, password); CF.query(datasource, sql, username, password, maxrows);
You can use the timeout parameter only if you used named parameters. Otherwise, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access