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:
- 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.
- 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:
- 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:
The following is an example connection string for OKTA MFA:
Authenticating with AzureADSet 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.
Authenticating with PingFederateSet 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.
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.