We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Import Real-Time IBM Cloud Object Storage Data in ColdFusion to Build Applications
Use CData ODBC drivers to import and use IBM Cloud Object Storage data in ColdFusion.
Adobe ColdFusion is a web and mobile application development platform. It uses its own scripting language, ColdFusion Markup Language (CFML), to create data-driven websites as well as generate remote services, such as REST. When ColdFusion is paired with the CData ODBC Driver for IBM Cloud Object Storage, you can link your ColdFusion web and mobile applications to operational IBM Cloud Object Storage data. This allows for your applications to be more robust and complete. This article details how to use the ODBC driver to create a table populated with IBM Cloud Object Storage data from within a ColdFusion markup file.
To follow along with this tutorial, you need to install the CData ODBC Driver for IBM Cloud Object Storage and Adobe ColdFusion.
Configuring the Connection
If you have not already, first specify connection properties in an ODBC DSN (Data Source Name). This is the last step of the driver installation process. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
Register a New Instance of Cloud Object Storage
If you do not already have Cloud Object Storage in your IBM Cloud account, follow the procedure below to install an instance of SQL Query in your account:
- Log in to your IBM Cloud account.
- Navigate to the page, choose a name for your instance and click Create. You will be redirected to the instance of Cloud Object Storage you just created.
Connecting using OAuth Authentication
There are certain connection properties you need to set before you can connect. You can obtain these as follows:
API Key
To connect with IBM Cloud Object Storage, you need an API Key. You can obtain this as follows:
- Log in to your IBM Cloud account.
- Navigate to the Platform API Keys page.
- On the middle-right corner click "Create an IBM Cloud API Key" to create a new API Key.
- In the pop-up window, specify the API Key name and click "Create". Note the API Key as you can never access it again from the dashboard.
Cloud Object Storage CRN
If you have multiple accounts, you will need to specify the CloudObjectStorageCRN explicitly. To find the appropriate value, you can:
- Query the Services view. This will list your IBM Cloud Object Storage instances along with the CRN for each.
- Locate the CRN directly in IBM Cloud. To do so, navigate to your IBM Cloud Dashboard. In the Resource List, Under Storage, select your Cloud Object Storage resource to get its CRN.
Connecting to Data
You can now set the following to connect to data:
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- ApiKey: Set this to your API key which was noted during setup.
- CloudObjectStorageCRN (Optional): Set this to the cloud object storage CRN you want to work with. While the connector attempts to retrieve this automatically, specifying this explicitly is recommended if you have more than Cloud Object Storage account.
When you connect, the connector completes the OAuth process.
- Extracts the access token and authenticates requests.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Adding a Data Source and Creating a Table
After creating a DSN, follow the steps below to add a new data source, test our connection to it, create a ColdFusion markup file, and, finally, import IBM Cloud Object Storage IBM Cloud Object Storage data and display it in a table in ColdFusion:
- From the ColdFusion administrator interface, choose Data & Services.
- Here, click "Add New Data Source". The data source name can be any name, provided it conforms to the ColdFusion variable naming conventions. For our ODBC driver, choose "ODBC Socket", then click the "Add" button.
- From the ODBC DSN Dropdown menu select CData IBM Cloud Object Storage Sys. Under the Advanced Settings section, leave the Connection String blank. Note that any properties specified in this input field will override the ones specified in the DSN Configuration.
- Now, test the connection by pressing the check mark to the left of the CDataIBM Cloud Object StorageODBC data source you just created. When the data source reports an "OK" status, it is ready for use.
-
Next, create a new ColdFusion Markup file (.cfm) and place it in the wwwroot directory ("C:\ColdFusion2021\cfusion\wwwroot")
for ColdFusion.
The following code queries the data source:
<cfquery name="IBM Cloud Object StorageQuery" dataSource="CDataIBM Cloud Object StorageODBC"> SELECT * FROM Objects </cfquery>
And a CFTable can be used to quickly output the table in HTML:<cftable query = "IBM Cloud Object StorageQuery" border = "1" colHeaders colSpacing = "2" headerLines = "2" HTMLTable maxRows = "500" startRow = "1"> <cfcol header="<b>Key</b>" align="Left" width=2 text="Key"/> <cfcol header="<b>Etag</b>" align="Left" width=15 text="Etag"/> ... </cftable>
Full code, including the HTML portion is available below:<html> <head><title>CData Software | IBM Cloud Object Storage Objects Table Demo </title></head> <body> <cfoutput>#ucase("IBM Cloud Object Storage Objects Table Demo")#</cfoutput> <cfquery name="IBM Cloud Object StorageQuery" dataSource="CDataIBM Cloud Object StorageODBC"> SELECT * FROM Objects </cfquery> <cftable query = "IBM Cloud Object StorageQuery" border = "1" colHeaders colSpacing = "2" headerLines = "2" HTMLTable maxRows = "500" startRow = "1"> <cfcol header="<b>Key</b>" align="Left" width=2 text="Key"/> <cfcol header="<b>Etag</b>" align="Left" width=15 text="Etag"/> ... </cftable> </body> </html>
- Finally, run the code in a browser. It produces a table populated with IBM Cloud Object Storage data!
As a note, the CData ODBC Drivers also support parameterized queries using the cfqueryparam element.
For example:
SELECT * FROM Account WHERE name =
Get Started Today
Download a free, 30-day trial of the CData ODBC Driver for IBM Cloud Object Storage and start building IBM Cloud Object Storage-connected applications with Adobe ColdFusion. Reach out to our Support Team if you have any questions.