Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Query Snowflake Data in ColdFusion
Write standard ColdFusion data access code to connect to Snowflake data.
The CData JDBC driver for Snowflake seamlessly integrates connectivity to Snowflake data with the rapid development tools in ColdFusion. This article shows how to connect to Snowflake data in ColdFusion and query Snowflake tables.
About Snowflake Data Integration
CData simplifies access and integration of live Snowflake data. Our customers leverage CData connectivity to:
- Reads and write Snowflake data quickly and efficiently.
- Dynamically obtain metadata for the specified Warehouse, Database, and Schema.
- Authenticate in a variety of ways, including OAuth, OKTA, Azure AD, Azure Managed Service Identity, PingFederate, private key, and more.
Many CData users use CData solutions to access Snowflake from their preferred tools and applications, and replicate data from their disparate systems into Snowflake for comprehensive warehousing and analytics.
For more information on integrating Snowflake with CData solutions, refer to our blog: https://www.cdata.com/blog/snowflake-integrations.
Getting Started
Create a JDBC Data Source for Snowflake in ColdFusion
The JDBC data source enables you to execute SQL from standard ColdFusion tags like cfquery and CFScript like executeQuery.
-
Copy the driver JAR and .lic file from the installation directory onto the ColdFusion classpath. For example, copy the files into C:\MyColdFusionDirectory\cfusion\wwwroot\WEB-INF\lib. Or, open the Java and JVM page in the ColdFusion Administrator and enter the path to the files in the ColdFusion Class Path box.
The JAR and license for the driver are located in the lib subfolder of the installation directory.
Restart the server after this step.
-
Add the driver as a data source:
From the ColdFusion administrator interface, expand the Data & Services node and click Data Sources. In the Add New Data Source section, enter a name for the data source and select Other in the Driver menu.
-
Populate the driver properties:
JDBC URL: Enter connection properties in the JDBC URL. The JDBC URL begins with jdbc:snowflake: and is followed by the connection properties in a semicolon-separated list of name=value pairs.
To connect to Snowflake:
- Set User and Password to your Snowflake credentials and set the AuthScheme property to PASSWORD or OKTA.
- Set URL to the URL of the Snowflake instance (i.e.: https://myaccount.snowflakecomputing.com).
- Set Warehouse to the Snowflake warehouse.
- (Optional) Set Account to your Snowflake account if your URL does not conform to the format above.
- (Optional) Set Database and Schema to restrict the tables and views exposed.
See the Getting Started guide in the CData driver documentation for more information.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Snowflake JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.snowflake.jar
Fill in the connection properties and copy the connection string to the clipboard.
A typical JDBC URL is below:
jdbc:snowflake:User=Admin;Password=test123;Server=localhost;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;
- Driver Class: Enter the driver class. The driver class is cdata.jdbc.snowflake.SnowflakeDriver.
- Driver Name: Enter a user-defined name for the driver.
- Username: Enter the username used to authenticate.
- Password: Enter the password used to authenticate.
You can now test the connection by enabling the CData Snowflake data source in the Actions column. After reporting a status of OK, the Snowflake data source is ready for use.
Execute Queries
The cfquery tag can pass SQL statements to Snowflake, including INSERT, UPDATE, and DELETE.. Use the cfqueryparam tag to create parameterized queries and prevent SQL injection through the query string.
Note: To use the cfquery and cfscript, create a .cfm file. Inside the .cfm file, write the code to execute the query (see below). Place the file directly in the root directory of your web server (e.g., wwwroot in Adobe ColdFusion). Restart the service after placing the file for the changes to take effect.
<cfquery name="SnowflakeQuery" dataSource="CDataSnowflake">
SELECT * FROM Products WHERE Id = <cfqueryparam value="#Id#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfdump var="#SnowflakeQuery#">
Below is the equivalent in CFScript:
<cfscript> result = queryExecute( "SELECT * FROM Products WHERE Id = ?", [ { value="1", cfsqltype="cf_sql_varchar" } ], { datasource="CDataSnowflake" } ); writeDump( var= result ); </cfscript>
You can then make requests to your .cfm like the following:
http://MyServer:8500/query.cfm?Id=1