JDBC Driver for Snowflake

Build 21.0.7958

Establishing a Connection

Creating a JDBC Data Source

You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for Snowflake consists of three basic steps:

  • Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
  • Provide the driver class. For example:
    cdata.jdbc.snowflake.SnowflakeDriver
  • Provide the JDBC URL. For example:
    jdbc:snowflake:url=https://myaccount.region.snowflakecomputing.com;user=Admin;password=test123;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;
    
    or
    
    jdbc:cdata:snowflake:url=https://myaccount.region.snowflakecomputing.com;user=Admin;password=test123;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;

    The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:snowflake:" or "jdbc:cdata:snowflake:" and can include any of the connection properties in name-value pairs separated with semicolons.

Connecting to Snowflake

In addition to providing authentication (see below) set the following properties to connect to a Snowflake database:

  • Url: Both AWS and Azure instances are supported. For example:
    • AWS: https://myaccount.region.snowflakecomputing.com
    • Azure: https://myaccount.region.azure.snowflakecomputing.com

Account is only required if your Url does not conform to the usual syntax containing the account name at the beginning. Snowflake provides the Account name needed in this case.

Optionally, you can set Database and Schema to restrict the tables and views returned by the driver.

Authenticating to Snowflake

The driver supports Snowflake user authentication, federated authentication, and SSL client authentication. To authenticate, set User and Password, and select the authentication method in the AuthScheme property.

Authenticating with Password

Set User and Password to a Snowflake user and set AuthScheme to PASSWORD.

Authenticating with Key Pair

The driver allows you to authenticate using key pair authentication by creating a secure token with the private key defined for your user account. To connect with this method, set AuthScheme to PRIVATEKEY and set the following values:

  • User: The user account to authenticate as.
  • PrivateKey: The private key used for the user such as the path to the .pem file containing the private key.
  • PrivateKeyType: The type of key store containing the private key such as PEMKEY_FILE, PFXFILE, etc.
  • PrivateKeyPassword: The password for the specified private key.

Authenticating with Okta

Set the AuthScheme to Okta. The following connection properties are used to connect to Okta:

  • User: Set this to the Okta user.
  • Password: Set this to Okta password for the user.
  • MFAPasscode (optional): Set this to the OTP code that was sent to your device. This property should be used only when the MFA is required for OKTA sign on.
The following SSOProperties are needed to authenticate to Okta:
  • Domain: Set this to the OKTA org domain name.
  • MFAType (optional): Set this to the multi-factor type. This property should be used only when the MFA is required for OKTA sign on. This property accepts one of the following values:
    • OKTAVerify
    • Email
    • SMS
  • APIToken (optional): Set this to the API Token that the customer created from the Okta org. It should be used when authenticating a user via a trusted application or proxy that overrides OKTA client request context.

The following is an example connection string:

AuthScheme=OKTA;User=username;Password=password;Url='https://myaccount.region.snowflakecomputing.com';Warehouse=My_warehouse;SSO Properties='Domain=https://cdata-okta.okta.com';

The following is an example connection string for OKTA MFA:

AuthScheme=OKTA;User=username;Password=password;MFAPasscode=8111461;Url='https://myaccount.region.snowflakecomputing.com';Warehouse=My_warehouse;SSO Properties='Domain=https://cdata-okta.okta.com;MFAType=OktaVerify;';

Authenticating with AzureAD

Set the AuthScheme to AzureAD. The following connection properties are used to connect to AzureAD:
  • User: Set this to your AD user. When connecting, your browser will open allowing you to login to Azure AD to complete the authentication.
The following is an example connection string for AzureAD:
AuthScheme=AzureAD;Url=https://myaccount.region.snowflakecomputing.com;User=user@domain.onmicrosoft.com;

Authenticating with PingFederate

Set the AuthScheme to PingFederate. The following connection properties are used to connect to PingFederate:
  • User: Set this to your PingFederate user, the user should been added to PingFederate Data Stores. When connecting, your browser will open allowing you to login to PingFederate to complete the authentication.
The following is an example connection string for PingFederate(Assuming that Active Directory is used as a Data Store):
AuthScheme=PingFederate;Url=https://myaccount.region.snowflakecomputing.com;User=myuser@mydomain;Account=myaccount;Warehouse=mywarehouse;

Authenticating with OAuth

To authenticate with OAuth, set the AuthScheme to OAuth. You can authenticate by Creating a Custom OAuth App to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties.

See Using OAuth Authentication for an authentication guide.

Configuring Access Control

If the authenticating user maps to a system-defined role, specify it in the RoleName property.

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7958