Configuring the JDBC Driver

This topic describes how to configure the JDBC driver, including how to connect to Snowflake using the driver.

Note

The connection parameters are now documented in the JDBC Driver connection parameter reference.

Runtime dependencies

The JDBC Driver 5.x packages include everything the driver needs, except an SLF4J binding if you choose to log through SLF4J (see Configuring JDBC logging). Don’t add the JNA libraries or the --add-opens JVM option that earlier versions needed.

On newer Java versions, start your application with --enable-native-access=ALL-UNNAMED so that the driver can load its native library. Don’t set this option on Java 8 or Java 11. For details, see Requirements for the JDBC Driver.

Add the JNA classes to your classpath (4.x)

Important

This section applies to JDBC Driver 4.x only. JDBC Driver 5.x doesn’t use JNA.

Connection caching for browser-based SSO and token caching for multi-factor authentication (MFA) require the use of the Java Native Access (JNA) classes to save data securely to the filesystem.

As of version 3.12.18 of the JDBC Driver, the JNA classes are no longer packaged in the JDBC Driver JAR file. In the JDBC Driver pom.xml file, the dependencies on these classes are marked as optional.

If you need to use connection caching or token caching, you must add the following libraries to your classpath:

The pom.xml file for the JDBC Driver specifies the version of the JNA classes that have been tested with the JDBC Driver. Snowflake recommends using this version (or the same major version) of the JNA classes.

For more information, see JDBC Driver page in the Maven Central Repository.

Note

For systems that use the aarch64 architecture (e.g. the Apple M1 chip), use version 5.7.0 or later of the JNA libraries. (JNA versions prior to v5.7.0 are not compatible with Windows and macOS systems that run on aarch64.)

JDBC Driver class

Use net.snowflake.client.api.driver.SnowflakeDriver as the driver class in your JDBC application.

Note

  • Don’t reference any other Snowflake classes or methods in your application code because they are subject to change in the future to implement improvements and fixes.
  • The previous driver class, net.snowflake.client.jdbc.SnowflakeDriver, is still supported but is deprecated (meaning it will be removed in a future release). Any code that references the previous class name will continue to work, but you should update the code to reference the new class name because the change has been implemented.

JDBC Driver connection string

Important

Beginning with Snowflake version 8.24, network administrators have the option to require multi-factor authentication (MFA) for all connections to Snowflake. If your administrator decides to enable this feature, you must configure your client or driver to use MFA when connecting to Snowflake. For more information, see the following resources:

Using the JDBC driver to connect to Snowflake requires a connection string with the syntax described below.

You can generate the basic connection string in Snowsight. For information, see Configuring a client, driver, library, or third-party application to connect to Snowflake.

Note

You cannot set the SEARCH_PATH parameter within a JDBC client connection string. You must establish a session before setting a search path.

Syntax

jdbc:snowflake://<account_identifier>.snowflakecomputing.com/?<connection_params>

Connection parameters

Note

For documentation on individual connection parameters, see the JDBC Driver connection parameter reference.

<account_identifier>

Specifies the account identifier for your Snowflake account. For details, see Configuring a client, driver, library, or third-party application to connect to Snowflake. For examples of the account identifier used in a JDBC connection string, see Examples.

<connection_params>

Specifies a series of one or more JDBC connection parameters and session parameters, in the form of <param>=<value>, with each parameter separated by the ampersand character (&), and no spaces anywhere in the connection string.

If you need to set parameter values that use spaces, ampersands (&), equals signs (=), or other special characters, you should URL-encode the special characters. For example, if you need to specify a value that contains a space, ampersand, and equals sign in the query_tag session parameter:

String connectionURL = "jdbc:snowflake://myorganization-myaccount.snowflakecomputing.com/?query_tag='folder=folder1 folder2&'

encode the space as %20, the ampersand as %26, and the equals sign as %3D:

String connectionURL = "jdbc:snowflake://myorganization-myaccount.snowflakecomputing.com/?query_tag='folder%3Dfolder1%20folder2%26'

As an alternative, rather than specifying these parameters in the connection string, you can set these parameters in a Properties object that you pass to the DriverManager.getConnection method.

Properties props = new Properties();
props.put("parameter1", parameter1Value);
props.put("parameter2", parameter2Value);
Connection con = DriverManager.getConnection("jdbc:snowflake://<account_identifier>.snowflakecomputing.com/", props);

Note

For documentation on individual connection parameters, see the JDBC Driver connection parameter reference.

Other parameters

Any session parameter can be included in the connection string. For example:

BROWSER_RESPONSE_TIMEOUT=<Integer>

Specifies the timeout, in seconds, to wait for a successful authentication from an external browser.

Default is 120.

CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED=<Boolean>

Specifies whether to enable out-of-band telemetry.

Default is true.

CLIENT_SESSION_KEEP_ALIVE=<Boolean>

Specifies whether to keep the current session active after a period of inactivity, or to force the user to login again. If the value is true, Snowflake keeps the session active indefinitely, even if there is no activity from the user. If the value is false, the user must log in again after four hours of inactivity.

Default is false.

CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY=<Integer>

Specifies the number of seconds (900-3600) in-between client attempts to update the token for the session.

Default is 3600.

net.snowflake.jdbc.commons_logging_wrapper

Important

This parameter is available in JDBC Driver 4.x only. JDBC Driver 5.x doesn’t use commons logging, so you don’t need this parameter. See Configuring JDBC logging.

Specifies how to handle logs from commons logging. Possible values are:

  • ALL: All logs from common logging are passed to SFLogger (java.util.logging or SLF4J is used internally).
  • Default: All logs from commons logging are forwarded to java.util.logging, and no logs are forwarded to the SLF4J logger.
  • OFF: No logs from commons logging are forwarded. You can use this value if you need to replace commons logging with the SLF4J bridge when using a thin JAR file.
JDBC_QUERY_RESULT_FORMAT=JSON

Specifies JSON as the result format to use while fetching or processing the results of a query sent to Snowflake.

Default is Arrow.

For descriptions of all the session parameters, see Parameters.

Examples

The following is an example of the connection string that uses the account name as an identifier for the account myaccount in the organization myorganization.

jdbc:snowflake://myorganization-myaccount.snowflakecomputing.com/?user=peter&warehouse=mywh&db=mydb&schema=public

The following is an example of a connection string that uses the account locator xy12345 as the account identifier:

jdbc:snowflake://xy12345.snowflakecomputing.com/?user=peter&warehouse=mywh&db=mydb&schema=public

Note that this example uses an account in the AWS US West (Oregon) region. If the account is in a different region or if the account uses a different cloud provider, you need to specify additional segments after the account locator.

Connecting using the connections.toml file

The JDBC driver lets you add connection definitions to a connections.toml configuration file. A connection definition refers to a collection of connection-related parameters. The driver currently supports TOML version 1.0.0.

For more information about toml file formats, see TOML (Tom’s Obvious Minimal Language).

The connection string prefix: jdbc:snowflake:auto tells the driver to look for the connection configuration within the predefined (default) files. The JDBC driver looks for the connection definitions in the following locations:

  1. The connections.toml file.
  2. The [connections.<connection_name>] tables in the config.toml file. If both files define a connection with the same name, the definition in connections.toml is used.

The driver looks for both files in the directory that the SNOWFLAKE_HOME environment variable specifies, if that directory exists. Otherwise, it uses the default Snowflake configuration directory for your operating system.

You can generate the basic settings for the TOML configuration file in Snowsight. For information, see Configuring a client, driver, library, or third-party application to connect to Snowflake.

If you want to switch between multiple existing connections, you can configure them in the connections.toml file. The default key is default, but you change the name of the default connection by setting the SNOWFLAKE_DEFAULT_CONNECTION_NAME shell environment variable.

The following sample connections.toml files defines three connections:

[default]
account = 'my_organization-my_account'
user = 'test_user'
warehouse = 'testw'
database = 'test_db'
schema = 'test_nodejs'
protocol = 'https'
port = '443'
authenticator = 'oauth'
token_file_path = '/Users/test/.snowflake/token'

[production]
account = 'my_organization-my_account'
user = 'prod_user'
warehouse = 'prodw'
database = 'prod_db'
schema = 'prod_nodejs'
protocol = 'https'
port = '443'
authenticator = 'oauth'
token_file_path = '/Users/test/.snowflake/token'


[aws-oauth-file]
account = 'my_organization-my_account'
user = 'test_user'
warehouse = 'testw'
database = 'test_db'
schema = 'test_nodejs'
protocol = 'https'
port = '443'
authenticator = 'oauth'
token_file_path = '/Users/test/.snowflake/token'

Specifying a connection to use in the auto connection prefix

You can specify which connection configuration to use by appending the connection name to the auto prefix in the connection string. Continuing the previous example, to connect with aws-oauth-file, use the following connection string:

jdbc:snowflake:auto?connectionName=aws-oauth-file

This connection string tells the JDBC driver to look for the aws-oauth-file connection definition in the connections.toml file.

The driver determines which connection to use in the following order:

  1. The connection name that you specify in the connectionName or connection_name property of the Properties object, if any. A value in Properties overrides a value in the connection string, and the property name isn’t case-sensitive.
  2. The connection name that you specify in the connection string using the jdbc:snowflake:auto?connectionName=<connection_name_in_toml_file> syntax
  3. The connection name in the SNOWFLAKE_DEFAULT_CONNECTION_NAME shell environment variable
  4. The default_connection_name value in the config.toml file
  5. The default connection name, default

The driver validates an auto connection string strictly. A malformed query string, a fragment, or the same option specified twice under different spellings fails with a SQLException for an invalid parameter value.

If the connection name that you specify doesn’t exist, the driver throws an exception that contains the name of the missing connection, in the following format, and terminates the connection attempt:

The Connection <connection name> not found in connections.toml file.

The exception has SQLSTATE 22023 and vendor code 200047.

The driver no longer applies the following option spellings in a connection definition: disableQueryContextCache, private_key_pwd, PRIVATE_KEY_PWD, PRIVATE_KEY_BASE64, wifHost, and workloadIdentityHost. Use disable_query_context_cache, PRIVATE_KEY_FILE_PWD, and workload_identity_host instead. The driver also no longer reads the default workload identity token file at /snowflake/session/token.

Using single sign-on (SSO) for authentication

If you have configured Snowflake to use single sign-on (SSO), you can configure your client application to use SSO for authentication. See Using SSO with client applications that connect to Snowflake for details.

Using multi-factor authentication

Snowflake supports caching MFA tokens, including combining MFA token caching with SSO.

For more information, see Using MFA token caching to minimize the number of prompts during authentication — *optional*.

Note

In JDBC Driver 5.x, the clientStoreTemporaryCredential property controls caching of MFA tokens, browser-based SSO tokens, and OAuth tokens. The default is true. The driver ignores clientRequestMfaToken and logs a warning. For where the driver stores the cached credentials, see File caches.

Using key pair authentication and key rotation

The Snowflake JDBC driver supports key pair authentication and key rotation. This authentication method requires a 2048-bit (minimum) RSA key pair.

To start, complete the initial configuration for key pair authentication as shown in Key-pair authentication and key-pair rotation.

Next, choose one of the following options to configure either the JDBC connection properties or the JDBC connection string.

  1. Specify the private key via the privateKey property in the connection properties, as a java.security.PrivateKey object.
  2. Specify the private key as a PEM string via the private_key property in the connection properties.
  3. Specify the private key file name and password for that file as separate properties in the connection properties.
  4. Specify the private key file name and password for that file as part of the connection string.

These options are described in more detail in the next four sections. Specify only one of them. For example, the driver rejects a connection that sets both private_key and private_key_file.

privateKey property in connection properties

This section provides an example of setting the privateKey property to a private key in a file.

Note

JDBC Driver 5.x decrypts private keys in its native library, so it doesn’t need Bouncy Castle. This example uses Bouncy Castle only to load the key into a java.security.PrivateKey object. If you don’t already have such an object, use the private_key property or the private_key_file property instead.

This example uses the Bouncy Castle Crypto APIs. In order to compile and run this example, you must include the following JAR files in your classpath:

  • the provider JAR file (bcprov-jdkversions.jar)
  • the PKIX / CMS / EAC / PKCS / OCSP / TSP / OPENSSL JAR file (bcpkix-jdkversions.jar)

where versions specifies the versions of the JDK that the JAR file supports.

To use this example:

  1. Copy the sample code below, and replace the following placeholder values:

    PlaceholderDescription
    path/rsa_key.p8Set this to the path and name of the private key file that you generated earlier.
    private_key_passphraseIf you generated an encrypted key, implement the getPrivateKeyPassphrase() method to return the passphrase for decrypting that key.
    account_identifierSet this to your account identifier.
    userSet this to your Snowflake login name.
    database_nameSet this to the name of the database that you want to use.
    schema_nameSet this to the name of the schema that you want to use.
    warehouse_nameSet this to the name of the warehouse that you want to use.
    roleSet this to the name of the role that you want to use.
  2. Compile and run the sample code. Include the Bouncy Castle JAR files in the classpath.

    For example, on Linux and macOS:

    javac -cp bcprov-jdk<versions>.jar:bcpkix-jdk<versions>.jar TestJdbc.java
    
    java -cp .:snowflake-jdbc-<ver>.jar:bcprov-jdk<versions>.jar:bcpkix-jdk<versions>.jar TestJdbc.java
    

    On Windows:

    javac -cp bcprov-jdk<versions>.jar;bcpkix-jdk<versions>.jar TestJdbc.java
    
    java -cp .;snowflake-jdbc-<ver>.jar;bcprov-jdk<versions>.jar;bcpkix-jdk<versions>.jar TestJdbc.java
    

Sample code

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder;
import org.bouncycastle.operator.InputDecryptorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo;
import org.bouncycastle.pkcs.PKCSException;

import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;
import java.security.PrivateKey;
import java.security.Security;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.util.Properties;

public class TestJdbc
{
  // Path to the private key file that you generated earlier.
  private static final String PRIVATE_KEY_FILE = "/<path>/rsa_key.p8";

  public static class PrivateKeyReader
  {

    // If you generated an encrypted private key, implement this method to return
    // the passphrase for decrypting your private key.
    private static String getPrivateKeyPassphrase() {
      return "<private_key_passphrase>";
    }

    public static PrivateKey get(String filename)
            throws Exception
    {
      PrivateKeyInfo privateKeyInfo = null;
      Security.addProvider(new BouncyCastleProvider());
      // Read an object from the private key file.
      PEMParser pemParser = new PEMParser(new FileReader(Paths.get(filename).toFile()));
      Object pemObject = pemParser.readObject();
      if (pemObject instanceof PKCS8EncryptedPrivateKeyInfo) {
        // Handle the case where the private key is encrypted.
        PKCS8EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = (PKCS8EncryptedPrivateKeyInfo) pemObject;
        String passphrase = getPrivateKeyPassphrase();
        InputDecryptorProvider pkcs8Prov = new JceOpenSSLPKCS8DecryptorProviderBuilder().build(passphrase.toCharArray());
        privateKeyInfo = encryptedPrivateKeyInfo.decryptPrivateKeyInfo(pkcs8Prov);
      } else if (pemObject instanceof PrivateKeyInfo) {
        // Handle the case where the private key is unencrypted.
        privateKeyInfo = (PrivateKeyInfo) pemObject;
      }
      pemParser.close();
      JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
      return converter.getPrivateKey(privateKeyInfo);
    }
  }

  public static void main(String[] args)
      throws Exception
  {
    String url = "jdbc:snowflake://<account_identifier>.snowflakecomputing.com";
    Properties prop = new Properties();
    prop.put("user", "<user>");
    prop.put("privateKey", PrivateKeyReader.get(PRIVATE_KEY_FILE));
    prop.put("db", "<database_name>");
    prop.put("schema", "<schema_name>");
    prop.put("warehouse", "<warehouse_name>");
    prop.put("role", "<role_name>");

    Connection conn = DriverManager.getConnection(url, prop);
    Statement stat = conn.createStatement();
    ResultSet res = stat.executeQuery("select 1");
    res.next();
    System.out.println(res.getString(1));
    conn.close();
  }
}

Note

Use forward slashes as file path separators on all operating systems, including Windows. The JDBC driver replaces forward slashes with the appropriate path separator for the platform.

Private key as a PEM string in connection properties

This option is available in JDBC Driver 5.x only.

You can specify the private key as a PEM string that begins with -----BEGIN. If the key is encrypted, also set the private_key_password property:

String privateKeyPem = new String(Files.readAllBytes(Paths.get("/tmp/rsa_key.p8")), StandardCharsets.UTF_8);

Properties props = new Properties();
props.put("user", "<user>");
props.put("authenticator", "SNOWFLAKE_JWT");
props.put("private_key", privateKeyPem);
props.put("private_key_password", "dummyPassword");
Connection connection = DriverManager.getConnection("jdbc:snowflake://myorganization-myaccount.snowflakecomputing.com", props);

If the PEM string is malformed, the connection fails with Invalid private key format.

Private key file name and password as connection properties

You can specify the private key file name and password as separate connection properties, for example:

Properties props = new Properties();
props.put("private_key_file", "/tmp/rsa_key.p8");
props.put("private_key_file_pwd", "dummyPassword");
Connection connection = DriverManager.getConnection("jdbc:snowflake://myorganization-myaccount.snowflake.com", props);

If you specify the private_key_file and private_key_file_pwd parameters, do not specify the privateKey parameter in the connection properties.

Note

Use forward slashes as file path separators on all operating systems, including Windows. The JDBC driver replaces forward slashes with the appropriate path separator for the platform.

Private key file name and password in connection string

You can specify the private key file name and password in the connection string, as shown below:

Connection connection = DriverManager.getConnection(
    "jdbc:snowflake://myorganization-myaccount.snowflake.com/?private_key_file=/tmp/rsa_key.p8&private_key_file_pwd=dummyPassword",
    props);

Note

Use forward slashes as file path separators on all operating systems, including Windows. The JDBC driver replaces forward slashes with the appropriate path separator for the platform.

If you specify the private key and password in the connection string, then do not specify the parameters private_key_file, private_key_file_pwd, or privateKey in the connection properties.

Key decryption errors

If you use encrypted keys that were generated using OpenSSL V3, you might receive errors similar to the following:

java.security.NoSuchAlgorithmException: 1.2.840.113549.1.5.13 SecretKeyFactory not available

java.security.InvalidKeyException: IOException : DER input, Integer tag error

In this situation, you can use Bouncy Castle to decrypt the key by specifying the following JVM argument:

JDBC Driver 5.x decrypts the private key in its native library, so you don’t need a JVM argument.

Using the OAuth 2.0 Authorization Code flow

The OAuth 2.0 Authorization Code flow is a secure method for a client application to obtain an access token from an authorization server on behalf of a user, without revealing the user’s credentials.

To enable the OAuth 2.0 Authorization Code flow:

  1. Set the authenticator connection parameter to oauth_authorization_code.
  2. Set the following OAuth connection parameters:
    • oauthClientId: Value of client id provided by the identity provider for Snowflake integration (Snowflake security integration metadata). Default: LOCAL_APPLICATION if unset and the IDP is Snowflake.
    • oauthClientSecret: Value of the client secret provided by the identity provider for Snowflake integration (Snowflake security integration metadata). Default: LOCAL_APPLICATION if unset and the IDP is Snowflake.
    • oauthAuthorizationUrl: Identity provider endpoint supplying the authorization code to the driver. When Snowflake is used as an identity provider, this value is derived from the server or account parameters.
    • oauthTokenRequestUrl: Identity provider endpoint supplying the access tokens to the driver. When Snowflake is used as an identity provider, this value is derived from the server or account parameters.
    • oauthScope: Scope requested in the identity provider authorization request. By default, it is derived from the role. When multiple scopes are required, the value should be a space-separated list of multiple scopes.
    • oauthRedirectUri: URI to use for authorization code redirection (Snowflake security integration metadata). Default: http://127.0.0.1:{randomAvailablePort}.

Note

In JDBC Driver 5.x, oauthAuthorizationUrl and oauthTokenRequestUrl must use HTTPS, except for loopback addresses. The driver rejects other http URLs when you connect. Earlier versions log a warning and use them.

Using the OAuth 2.0 Client Credentials flow

The OAuth 2.0 Client Credentials flow provides a secure way for machine-to-machine (M2M) authentication, such as the Snowflake Connector for Python connecting to a backend service. Unlike the OAuth 2.0 Authorization Code flow, this method does not rely on any user-specific data.

To enable the OAuth 2.0 Client Credentials flow:

  1. Set the authenticator connection parameter to oauth_client_credentials.
  2. Set the following OAuth connection parameters:
    • oauthClientId: Value of client id provided by the identity provider for Snowflake integration (Snowflake security integration metadata).
    • oauthClientSecret: Value of the client secret provided by the identity provider for Snowflake integration (Snowflake security integration metadata)
    • oauthTokenRequestUrl: Identity provider endpoint supplying the access tokens to the driver.
    • oauthScope: Scope requested in the identity provider authorization request. By default, it is derived from the role. When multiple scopes are required, the value should be a space-separated list of multiple scopes.

Note

In JDBC Driver 5.x, oauthTokenRequestUrl must use HTTPS, except for loopback addresses. The driver rejects other http URLs when you connect. Earlier versions log a warning and use them.

Authenticating with a programmatic access token (PAT)

Programmatic access token (PAT) is a Snowflake-specific authentication method. The feature must be enabled for the account before usage (see the Prerequisites for more information). Authentication with PAT doesn’t involve any human interaction.

Authenticating with workload identity federation (WIF)

Workload identity federation provides a service-to-service authentication method for Snowflake. This method enables applications, services, or containers to authenticate with Snowflake by leveraging their cloud provider’s native identity system, such as AWS IAM, Microsoft Entra ID, or Google Cloud service accounts. This approach eliminates the need for managing long-lived credentials and simplifies credential acquisition compared to other methods like External OAuth. Snowflake connectors are designed to automatically obtain short-lived credentials from the platform’s identity provider.

To enable the workload identity federation authenticator, do the following:

  1. Set the authenticator connection parameter to WORKLOAD_IDENTITY.
  2. Set the workloadIdentityProvider connection parameter to AWS, AZURE, GCP, or OIDC, based on your platform.
  3. For OpenID Connect (OIDC), specify the token connection parameter.

Note

In JDBC Driver 5.x:

  • A workloadIdentity* parameter that you set with any other authenticator causes the connection to fail instead of being ignored.
  • With the OIDC provider, specifying workloadIdentityImpersonationPath fails the connection. Remove it.
  • The workloadIdentityAwsExternalId parameter isn’t supported with the AWS provider. Specifying a value fails the connection.

Rotating OIDC tokens (Kubernetes)

The token parameter is a static value that’s read when the connection is created. For workload identity federation, the driver doesn’t read the token from a file, and it doesn’t watch a token file for changes. The token_file_path option in connections.toml applies only to the OAuth authenticator.

In Kubernetes environments such as Amazon EKS, Azure AKS, and Google GKE, projected service account tokens rotate. Your application must read the token file itself and pass the current value as the token parameter each time it opens a new connection.

The driver uses the OIDC token only to log in. When the OIDC token expires, an open connection isn’t affected, because the driver renews the session without it. New connections, including connections that a connection pool opens, must use the current token from the file.

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

String token = new String(Files.readAllBytes(Paths.get("<service_account_token_path>")), StandardCharsets.UTF_8).trim();

Properties props = new Properties();
props.put("authenticator", "WORKLOAD_IDENTITY");
props.put("workloadIdentityProvider", "OIDC");
props.put("token", token);

Connection conn = DriverManager.getConnection("jdbc:snowflake://<account_identifier>.snowflakecomputing.com", props);

For more information about workload identity federation, see Workload identity federation.

Verifying the network connection to Snowflake with SnowCD

After configuring your driver, you can evaluate and troubleshoot your network connectivity to Snowflake using SnowCD.

You can use SnowCD during the initial configuration process and on-demand at any time to evaluate and troubleshoot your network connection to Snowflake.

Connecting using a proxy server

You can use a proxy server with the Snowflake JDBC Driver in the following ways:

Note

Proxy settings specified in the connection string take precedence over JVM system properties.

Note

In JDBC Driver 5.x:

  • The JVM system properties apply only when the connection doesn’t set a proxy. For each proxy, you must set both the host and the port.
  • The driver merges the NO_PROXY environment variable into http.nonProxyHosts.
  • The socksProxyHost and socksProxyPort system properties and java.net.useSystemProxies don’t apply, and the disableSocksProxy parameter doesn’t change routing.

Tip

Snowflake’s security model does not allow Transport Layer Security (TLS) proxies (using an HTTPS certificate). Your proxy server must use a publicly-available Certificate Authority (CA), reducing potential security risks such as a MITM (Man In The Middle) attack through a compromised proxy.

If you must use your TLS proxy, we strongly recommend that you update the server policy to pass through the Snowflake certificate such that no certificate is altered in the middle of communications.

As an alternative, you can set the nonProxyHosts parameter in the connection string or Properties object to bypass the proxy for specific communications. For example, Amazon S3 access can be bypassed by specifying nonProxyHosts=".amazonaws.com".

Specifying a proxy server by setting Java system properties

To connect through a proxy server, you can set the proxy system properties. You can either set these in your code or pass them on the command line to the JVM (Java virtual machine) for your client application.

For more information, see Java Networking and Proxies.

To set the system properties in your code, call System.setProperty:

System.setProperty("http.useProxy", "true");
System.setProperty("http.proxyHost", "proxyHost Value");
System.setProperty("http.proxyPort", "proxyPort Value");
System.setProperty("http.proxyUser", "proxyUser Value");
System.setProperty("http.proxyPassword", "proxyPassword Value");
System.setProperty("https.proxyHost", "proxyHost HTTPS Value");
System.setProperty("https.proxyPort", "proxyPort HTTPS Value");
System.setProperty("https.proxyUser", "proxyUser HTTPS Value");
System.setProperty("https.proxyPassword", "proxyPassword HTTPS Value");
System.setProperty("http.proxyProtocol", "https");

To pass the system properties on the command line to your JVM, use the -D command-line option:

-Dhttp.useProxy=true
-Dhttps.proxyHost=<proxy_host>
-Dhttps.proxyPort=<proxy_port>
-Dhttps.proxyUser=<proxy_user>
-Dhttps.proxyPassword=<proxy_password>
-Dhttp.proxyHost=<proxy_host>
-Dhttp.proxyPort=<proxy_port>
-Dhttp.proxyUser=<proxy_user>
-Dhttp.proxyPassword=<proxy_password>
-Dhttp.proxyProtocol="https"

To bypass the proxy for one or more IP addresses or hosts, set the http.nonProxyHosts system property to the list of these hosts:

  • Use a pipe symbol (|) to separate the host names.
  • To specify hostnames that match a pattern, use an asterisk (*) as a wildcard character.

The following example demonstrates how to set this system property on the command line:

-Dhttp.nonProxyHosts="*.example.com%localhost%myorganization-myaccount.snowflakecomputing.com|192.168.91.*"

Specifying a proxy server in the JDBC connection string

Note

Specifying the proxy information as part of the URL is less secure than other methods of specifying the proxy information.

To use a proxy server by setting the following parameters in the JDBC connection string:

If your proxy server does not require authentication, you can omit the proxyUser and proxyPassword parameters.

If your proxy server connection requires authentication using a proxy username and proxy password, those credentials may be exposed as plain text by other applications when using the HTTP protocol. To avoid exposing these credentials, use the proxyProtocol parameter to specify the HTTPS protocol.

jdbc:snowflake://<account_identifier>.snowflakecomputing.com/?warehouse=<warehouse_name>&useProxy=true&proxyHost=<ip_address>&proxyPort=<port>&proxyUser=test&proxyPassword=test

For example:

jdbc:snowflake://myorganization-myaccount.snowflakecomputing.com/?warehouse=DemoWarehouse1&useProxy=true&proxyHost=172.31.89.76&proxyPort=8888&proxyUser=test&proxyPassword=test

The proxy settings specified in the connection string take precedence over JVM system properties.

If the proxy JVM arguments are set and you do not want to proxy any of your connections, do not set useProxy=false, as it has no effect. Instead, use the following, which effectively bypasses the JVM proxy settings:

useProxy=true
proxyHost=127.0.0.1
proxyPort=8080
nonProxyHosts=*

Bypassing the Proxy Server

If you need to bypass the proxy server when connecting to one or more hosts, specify the list of hosts in the nonProxyHosts parameter:

&nonProxyHosts=<bypass_proxy_for_these_hosts>

Separate the hostnames with a URL-escaped pipe symbol (%7C). You can also use an asterisk (*) as a wildcard. For example:

&nonProxyHosts=*.example.com%7Clocalhost%7Cmyorganization-myaccount.snowflakecomputing.com%7C192.168.91.*

Note

In JDBC Driver 5.x, matching works as follows:

  • An entry such as foo.com bypasses foo.com and its subdomains. JDBC Driver 4.x bypasses only the exact host.
  • A * entry bypasses domain names but not IP addresses.
  • To bypass a range of IP addresses, use CIDR notation, for example 10.0.0.0/8. A wildcard pattern such as 192.168.* isn’t treated as a CIDR range.
  • Matching is case-sensitive.

Specifying the Protocol Used to Connect to the Proxy Server

  • To specify the protocol used to connect to the proxy server, use the proxyProtocol parameter. The default value is http, but https is also valid.

For example:

&proxyProtocol=https

OCSP and certificate revocation checking

When the driver connects, Snowflake sends a certificate to confirm that the connection is to Snowflake rather than to a host that is impersonating Snowflake.

Drivers built on the Universal Core do not support OCSP-based certificate revocation checking. Revocation checking is available only through CRLs (certificate revocation lists), and it is off by default.

If you require revocation checking, enable CRL checking and evaluate it in a non-production environment under a realistic workload. Confirm that your network allows outbound access to the CRL distribution points named in Snowflake’s certificate chain: a driver that cannot reach a distribution point cannot complete a revocation check.

To enable CRL checking, set the crl_check_mode connection property to one of the following values:

  • ENABLED: Checks the certificate against the CRLs and fails the connection (fail-close) if the check can’t be completed or the certificate is revoked.
  • ADVISORY: Checks the certificate against the CRLs, but doesn’t fail the connection (fail-open) if the check can’t be completed.
  • DISABLED: Doesn’t check certificate revocation. This is the default.
Properties props = new Properties();
props.put("crl_check_mode", "ENABLED");

The ocspFailOpen property is still accepted, but it doesn’t check any certificate. The net.snowflake.jdbc.ocspFailOpen and net.snowflake.jdbc.ocspResponseCacheDir system properties and the disableOCSPChecks and insecureMode parameters no longer have an effect.

Choosing fail-open or fail-close mode

Important

This section applies to JDBC Driver 4.x and earlier. JDBC Driver 5.x doesn’t use OCSP.

JDBC Driver versions prior to 3.8.0 default to fail-close. Versions 3.8.0 and later default to fail-open. You can override the default behavior in any of the following ways:

  • Set the connection property ocspFailOpen to true or false. For example:

    Properties connection_properties = new Properties();
    connection_properties.put("ocspFailOpen", "false");
    ...
    connection = DriverManager.getConnection(connectionString, connection_properties);
    
  • Set the system property net.snowflake.jdbc.ocspFailOpen to true or false. For example:

    Properties p = new Properties(System.getProperties());
    p.put("net.snowflake.jdbc.ocspFailOpen", "false");
    System.setProperties(p);
    

Verifying the OCSP connector or driver version

Important

This section applies to JDBC Driver 4.x and earlier. JDBC Driver 5.x doesn’t use OCSP.

For more information about the driver or connector version, configuration, and OCSP behavior, see OCSP Configuration.

OCSP response cache server

Important

The OCSP response cache server is available in JDBC Driver 3.6.0 through 4.x only. JDBC Driver 5.x doesn’t use OCSP or the OCSP response cache server.

Snowflake clients initiate every connection to a Snowflake service endpoint with a “handshake” that establishes a secure connection before actually transferring data. As part of the handshake, a client authenticates the TLS certificate for the service endpoint. The revocation status of the certificate is checked by sending a client certificate request to one of the OCSP (Online Certificate Status Protocol) servers for the CA (certificate authority).

A connection failure occurs when the response from the OCSP server is delayed beyond a reasonable time. The following caches persist the revocation status, helping alleviate these issues:

  • Memory cache, which persists for the life of the process.

  • File cache, which persists until the cache directory (e.g. ~/.cache/snowflake or ~/.snowsql/ocsp_response_cache) is purged.

  • Snowflake OCSP response cache server, which fetches OCSP responses from the CA’s OCSP servers hourly and stores them for 24 hours. Clients can then request the validation status of a given Snowflake certificate from this server cache.

    Important

    If your server policy denies access to most or all external IP addresses and web sites, you must allowlist the cache server address to allow normal service operation. The cache server hostname is ocsp*.snowflakecomputing.com:80.

    If you need to disable the cache server for any reason, set the SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED environment variable to false. Note that the value is case-sensitive and must be in lowercase.

If none of the cache layers contain the OCSP response, the client then attempts to fetch the validation status directly from the OCSP server for the CA.

File caches

To improve usability, the driver caches the tokens that it obtains during authentication: ID tokens for browser-based SSO, MFA tokens, and OAuth access and refresh tokens. Caching is enabled by default. To disable it, set the clientStoreTemporaryCredential connection property to false.

The driver stores the cached tokens as follows:

  • On macOS, in the macOS Keychain.

  • On Windows, in Windows Credential Manager.

  • On Linux, in the D-Bus Secret Service or the kernel keyutils keystore. If neither is available, the driver writes the tokens to a credential_cache_v2.json file, in a directory that only the current user can access. The driver looks for the directory in the following locations, in order:

    1. The directory that the SF_TEMPORARY_CREDENTIAL_CACHE_DIR environment variable specifies. The directory must exist.
    2. $XDG_CACHE_HOME/snowflake
    3. ~/.cache/snowflake

If your application runs on a shared Linux host without a system keystore, and you don’t want the driver to write tokens to a file, disable caching.

The JVM options -Dnet.snowflake.jdbc.temporaryCredentialCacheDir and -Dnet.snowflake.jdbc.ocspResponseCacheDir aren’t supported. Use the environment variable instead. The driver doesn’t cache OCSP responses.

Configuring JDBC logging

The driver delivers messages from its Java classes and from its native library to your application’s logger. Native library messages use the net.snowflake.client.CoreLogger logger. DEBUG is the finest level. To set the level, configure both the net.snowflake.client and net.snowflake.client.CoreLogger loggers.

The driver supports the following logging frameworks:

JDBC Driver 5.x doesn’t read the sf_client_config.json logging configuration file or the client_config_file connection parameter, and it doesn’t use commons-logging.

To select the logging framework, set the net.snowflake.jdbc.loggerImpl JVM option. If you don’t set it, or if you set it to an unrecognized value, the driver uses java.util.logging.

When you use java.util.logging and set the tracing connection property to a java.util.logging level name, such as INFO or FINE, the driver writes the log to %h/snowflake_jdbc%u.log, where %h is your home directory. The driver doesn’t do this when you set the java.util.logging.config.file system property or when you use SLF4J.

To write diagnostic information to a file for Snowflake Support, set the SNOWFLAKE_TROUBLESHOOTING_ENABLED environment variable to true before you start the process. The driver writes sf_driver_troubleshooting.log to the directory that the SNOWFLAKE_TROUBLESHOOTING_REPORT_PATH environment variable specifies, or to the current directory if the variable isn’t set.

Java core logging facilities (Java.util.logging)

By default, the java.util.logging uses ConsoleHandler to write to the standard error stream. You can set the Boolean JAVA_LOGGING_CONSOLE_STD_OUT Java system property to true (for example, -DJAVA_LOGGING_CONSOLE_STD_OUT=true), which writes all logs to the standard output stream. The default value is false. You can’t set this property as a connection property.

If you enable JAVA_LOGGING_CONSOLE_STD_OUT, you can also set the JAVA_LOGGING_CONSOLE_STD_OUT_THRESHOLD Java system property to set the maximum log level the driver should write to standard output. Any log messages with a higher level than specified are sent to standard error. Possible values for this property include:

  • OFF
  • SEVERE
  • WARNING
  • INFO
  • CONFIG
  • FINE
  • FINER
  • FINEST
  • ALL

java.util.logging is the default logger. To choose it explicitly, specify the following option for the JVM:

-Dnet.snowflake.jdbc.loggerImpl=net.snowflake.client.log.JDK14Logger

Then, you can customize the logging configuration using the application programming interface (API) for the logger.

For more details, see the java.util.logging Package documentation.

For example, create a file named logging.properties that includes the following contents:

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

.level = INFO

java.util.logging.FileHandler.pattern = /tmp/snowflake_jdbc%u.log
java.util.logging.FileHandler.limit = 5000000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

net.snowflake.client.level = INFO
net.snowflake.client.CoreLogger.level = INFO

Specify the JVM parameters before the -jar option on the command line:

java -Dnet.snowflake.jdbc.loggerImpl=net.snowflake.client.log.JDK14Logger -Djava.util.logging.config.file=logging.properties -jar application.jar

Where application.jar references the application code for the JDBC driver. The log files are located in /tmp/snowflake_jdbc*.

Simple logging facade for Java (org.slf4j)

To choose this logger, set the JVM option:

-Dnet.snowflake.jdbc.loggerImpl=net.snowflake.client.log.SLF4JLogger.

You must add slf4j-api and its implementation (for example, logback) to the classpath. The JDBC Driver 5.x packages don’t include slf4j-api.

For more information, see the Simple Logging Facade for Java (SLF4J) documentation.

Bridging logs from commons-logging

Important

This section applies to JDBC Driver 4.x only. JDBC Driver 5.x doesn’t use commons logging.

Some of the libraries use Apache commons-logging for logging. Handling these logs is configured by the net.snowflake.jdbc.commons_logging_wrapper JVM option that was added in version 3.22.0. For details, see Other parameters.

Logging configuration file

Important

This section applies to JDBC Driver 4.x only. JDBC Driver 5.x doesn’t read the sf_client_config.json file or the client_config_file connection parameter.

Alternatively, you can easily specify the log level and the directory in which to save log files in the sf_client_config.json configuration file.

Note

This logging configuration file feature supports only the following log levels:

  • DEBUG
  • ERROR
  • INFO
  • OFF
  • TRACE
  • WARNING

This configuration file uses JSON to define the log_level and log_path logging parameters, as follows:

{
  "common": {
    "log_level": "DEBUG",
    "log_path": "/home/user/logs"
  }
}

The driver looks configuration details in the following order:

  • client_config_file connection parameter, containing the full path to the user-defined logging configuration file. For example:

    client_config_file=/opt/snowflake/snowflake_jdbc/my_jdbc_config.json
    
  • SF_CLIENT_CONFIG_FILE environment variable, containing the full path to the user-defined logging configuration file.

    export SF_CLIENT_CONFIG_FILE=/home/myuser/my_jdbc_config.json
    
  • JDBC driver installation directory, where the file must be named sf_client_config.json.

  • User’s home directory, where the file must be named sf_client_config.json.

Note

  • If the configuration file is not found in any of the preceding locations, the driver uses the Java core logging facilities.
  • If a configuration file specified in either the client_config_file connection parameter or SF_CLIENT_CONFIG_FILE environment variable cannot be found or read, the driver throws an error message.

Disabling PUT and GET commands

By default, the JDBC driver allows you to execute PUT and GET commands. If you don’t want to allow PUT and GET commands access to the local file system, you can disable these commands in the following ways:

HTTP headers customization feature in Snowflake JDBC driver

Important

This feature is available in JDBC Driver 4.x and earlier. JDBC Driver 5.x doesn’t include the HttpHeadersCustomizer interface or the setHttpHeadersCustomizers method and has no replacement.

To programmatically add custom HTTP headers to requests made by the Snowflake JDBC driver, implement the HttpHeadersCustomizer interface and register your implementation(s). This allows flexible, programmatic injection of dynamic or static headers.

Key considerations:

  • The driver iterates registered customizers for applicable requests (Snowflake API, S3, private link OCSP). Then it calls applies(), then newHeaders() (respecting invokeOnce() for retries).
  • Customizers cannot override essential driver-set headers. This is enforced by the driver.
  • Keep applies() and newHeaders() efficient.

The following example shows how to implement net.snowflake.client.jdbc.HttpHeadersCustomizer.

public class MyDynamicCustomizer implements HttpHeadersCustomizer {
    public boolean applies(String method, String uri, Map<String, List> headers) {
        return true;
    }

    public Map<String, List<String>> newHeaders() {
        Map<String, List<String>> headers = new HashMap<>();
        headers.put("X-Dynamic-Token", Collections.singletonList("token-" + System.nanoTime()));
        return headers;
    }

    public boolean invokeOnce() {
        return false;
    }
}

The following examples show different ways to register customizers:

  • Via net.snowflake.client.jdbc.SnowflakeBasicDataSource:

    SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource();
    // ... set URL, user, password ...
    List<HttpHeadersCustomizer> myCustomizers = new ArrayList<>();
    myCustomizers.add(new MyDynamicHeaderCustomizer());
    Properties props = new Properties();
    props.put(HttpHeadersCustomizer.HTTP_HEADER_CUSTOMIZERS_PROPERTY_KEY, myCustomizers);
    ds.setConnectionProperties(props);
    
  • Via java.sql.DriverManager:

    Properties props = new Properties();
    // ... set user, password ...
    List<HttpHeadersCustomizer> myCustomizers = new ArrayList<>();
    myCustomizers.add(new MyDynamicHeaderCustomizer());
    props.put(HttpHeadersCustomizer.HTTP_HEADER_CUSTOMIZERS_PROPERTY_KEY, myCustomizers);
    Connection conn = DriverManager.getConnection(jdbcUrl, props);
    

Troubleshooting tips

Ensure properties are set correctly

The DriverManager.getConnection() method reads only the values of the Properties parameter that match specific, predefined names (“password”, “warehouse”, etc.). If you misspell a property name, or include extra properties, the driver ignores those properties without issuing an error or warning message. This can make it difficult to detect minor misspellings.

Use the right values for connection string and account

If you can’t establish a connection, verify that you are specifying the account identifier correctly in the JDBC connection string. For more information about finding your account identifier, see Configuring a client, driver, library, or third-party application to connect to Snowflake.