Programming instructions
Using SQL with ColdFusion 33
Using SQL with ColdFusion
ColdFusion communicates with your data source through a database interface called
JDBC. JDBC is a standard application programming interface (API) for accessing
information from different database systems and different storage formats.
About data sources
A data source is a complete database configuration that uses a JDBC driver to
communicate with a specific database. In ColdFusion, you must configure a data source
for each database file that you want to use. After you configure a data source, the
ColdFusion server is then capable of communicating with that data source through the
JDBC driver.
You configure data sources in ColdFusion by using the ColdFusion administrator.
Chapter 4, “Configuring Your Development Environment” on page 35 discusses how to
configure the sample data source file that is supplied for use with Part II of this book. For
more information about configuring a data source in ColdFusion, see Installing
ColdFusion MX or Developing ColdFusion MX Applications with CFML.
Writing SQL and CFML statements to interact with a data source
After ColdFusion makes a connection to the data source, you can interact with that
database by using SQL and ColdFusion.
To interact with an established data source, you need to include SQL statements in your
CFML statements; for example:
<cfquery name="queryname" datasource="namedbfile">
SELECT FirstName, LastName, DepartmentID
From Employee
</cfquery>
In the previous example, the first attribute of cfquery is the name of the query. The
second attribute of
cfquery defines the name of the data source. The SELECT statement
defines the fields (columns) to be retrieved from a tabled named
Employee.
CFML tags that interact with a database
The following table lists the CFML tags you can use to interact with a database:
In Part II of this book, you will be introduced to these tags when you use them to interact
with the sample database. For more information about interacting with a database, see
Developing ColdFusion MX Applications with CFML or CFML Reference.
Command Description
cfquery
To retrieve (query) information in a database.
cfinsert
To add records to a database.
cfupdate
To update information in a database.