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.
The standard snowflake-jdbc JAR file bundles most of the libraries that the driver needs. To use connection caching and token
caching, add Java Native Access (JNA) to your classpath.
If you manage dependencies yourself, use the snowflake-jdbc-thin artifact instead, which doesn’t bundle third-party libraries.
Note
On Java 16 and later, the driver might fail with errors about illegal reflective access when it reads query results in Arrow format. To resolve this, start your application with the following JVM option:
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:
-
For Mac and Linux:
-
For Windows:
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.
Use net.snowflake.client.jdbc.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,
com.snowflake.client.jdbc.SnowflakeDriver, is still supported but is deprecated (meaning it will be removed in a future release, TBD). 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¶
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:encode the space as
%20, the ampersand as%26, and the equals sign as%3D:As an alternative, rather than specifying these parameters in the connection string, you can set these parameters in a
Propertiesobject that you pass to theDriverManager.getConnectionmethod.
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 isfalse, 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_wrapperImportant
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 toSFLogger(java.util.loggingor SLF4J is used internally).Default: All logs from commons logging are forwarded tojava.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=JSONSpecifies
JSONas 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.
The following is an example of a connection string that uses the account locator
xy12345 as the account identifier:
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:
- The
connections.tomlfile. - The
[connections.<connection_name>]tables in theconfig.tomlfile. If both files define a connection with the same name, the definition inconnections.tomlis 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.
The driver looks for the connections.toml file in the following locations, in order:
- The location specified by the
SNOWFLAKE_HOMEenvironment variable. - The
~/.snowflake/connections.tomlfile, if the~/.snowflakedirectory exists.
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:
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:
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:
- The connection name that you specify in the
connectionNameorconnection_nameproperty of thePropertiesobject, if any. A value inPropertiesoverrides a value in the connection string, and the property name isn’t case-sensitive. - The connection name that you specify in the connection string using the
jdbc:snowflake:auto?connectionName=<connection_name_in_toml_file>syntax - The connection name in the
SNOWFLAKE_DEFAULT_CONNECTION_NAMEshell environment variable - The
default_connection_namevalue in theconfig.tomlfile - 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.
The driver determines which connection to use in the following order:
- Connection name specified in the connection string using the
jdbc:snowflake:auto?connectionName=<connection_name_in_toml_file>syntax - Connection name specified in the
SNOWFLAKE_DEFAULT_CONNECTION_NAMEshell environment variable - The default connection name,
default
If the connection name specified in the connection string does not exist in the connections.toml file, the driver does the following:
-
Logs a message indicating the missing name and the file path checked.
-
Throws an exception containing the name of the missing connection, in the following format:
The Connection <connection name> not found in connections.toml file. -
Terminates the connection attempt.
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.
- Specify the private key via the
privateKeyproperty in the connection properties, as ajava.security.PrivateKeyobject. - Specify the private key as a PEM string via the
private_keyproperty in the connection properties. - Specify the private key file name and password for that file as separate properties in the connection properties.
- 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.
- Specify the private key via the privateKey property in the connection properties.
- Specify the private key file name and password for that file as separate properties in the connection properties.
- 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 three sections.
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:
-
Copy the sample code below, and replace the following placeholder values:
Placeholder Description 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. -
Compile and run the sample code. Include the Bouncy Castle JAR files in the classpath.
For example, on Linux and macOS:
On Windows:
Sample code
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:
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:
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:
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:
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.
The default value is true, which means that the bundled Bouncy Castle library is used to decrypt the key.
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:
- Set the
authenticatorconnection parameter tooauth_authorization_code. - Set the following OAuth connection parameters:
oauthClientId: Value ofclient idprovided by the identity provider for Snowflake integration (Snowflake security integration metadata). Default:LOCAL_APPLICATIONif unset and the IDP is Snowflake.oauthClientSecret: Value of theclient secretprovided by the identity provider for Snowflake integration (Snowflake security integration metadata). Default:LOCAL_APPLICATIONif 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 theserveroraccountparameters.oauthTokenRequestUrl: Identity provider endpoint supplying the access tokens to the driver. When Snowflake is used as an identity provider, this value is derived from theserveroraccountparameters.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:
- Set the
authenticatorconnection parameter tooauth_client_credentials. - Set the following OAuth connection parameters:
oauthClientId: Value ofclient idprovided by the identity provider for Snowflake integration (Snowflake security integration metadata).oauthClientSecret: Value of theclient secretprovided 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:
- Set the
authenticatorconnection parameter toWORKLOAD_IDENTITY. - Set the
workloadIdentityProviderconnection parameter toAWS,AZURE,GCP, orOIDC, based on your platform. - For OpenID Connect (OIDC), specify the
tokenconnection 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
OIDCprovider, specifyingworkloadIdentityImpersonationPathfails the connection. Remove it. - The
workloadIdentityAwsExternalIdparameter isn’t supported with theAWSprovider. 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.
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:
- Set system properties for your proxy settings in the JVM (Java Virtual Machine) for your client application.
- Include the proxy host and port information in the JDBC connection string or the
Propertiesobject passed to theDriverManager.getConnection()method.
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_PROXYenvironment variable intohttp.nonProxyHosts. - The
socksProxyHostandsocksProxyPortsystem properties andjava.net.useSystemProxiesdon’t apply, and thedisableSocksProxyparameter 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:
To pass the system properties on the command line to your JVM, use the -D command-line option:
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:
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.
For example:
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:
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:
Separate the hostnames with a URL-escaped pipe symbol (%7C). You can also use an asterisk (*) as a wildcard. For example:
Note
In JDBC Driver 5.x, matching works as follows:
- An entry such as
foo.combypassesfoo.comand 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 as192.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
proxyProtocolparameter. The default value ishttp, buthttpsis also valid.
For example:
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.
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.
The driver sends that certificate to an OCSP (Online Certificate Status Protocol) server to verify that the certificate has not been revoked.
If the driver cannot reach the OCSP server to verify the certificate, the driver can “fail open” or “fail closed”.
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
ocspFailOpentotrueorfalse. For example: -
Set the system property
net.snowflake.jdbc.ocspFailOpentotrueorfalse. For example:
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/snowflakeor~/.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_ENABLEDenvironment variable tofalse. 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.jsonfile, in a directory that only the current user can access. The driver looks for the directory in the following locations, in order:- The directory that the
SF_TEMPORARY_CREDENTIAL_CACHE_DIRenvironment variable specifies. The directory must exist. $XDG_CACHE_HOME/snowflake~/.cache/snowflake
- The directory that the
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.
To improve usability, the driver uses file caches for authentication and OCSP responses. By default, these files are stored in the following directories:
- Linux:
~/.cache/snowflake- macOS:
~/Library/Caches/Snowflake- Windows:
%USERPROFILE%AppDataLocalSnowflakeCaches
If the JDBC application user does not have a user profile in the local operating system, the driver attempts to store the cache files in the temporary directory. You can configure the driver to write cache files to another directory using the following environment variables:
SF_TEMPORARY_CREDENTIAL_CACHE_DIR=stringSpecifies the location of the temporary credential cache file in a local directory. This can also be configured with the JVM option
-Dnet.snowflake.jdbc.temporaryCredentialCacheDir=stringon launch.SF_OCSP_RESPONSE_CACHE_DIR=stringSpecifies the location of the OCSP response cache file in a local directory. This can also be configured with the JVM option
-Dnet.snowflake.jdbc.ocspResponseCacheDir=stringon launch.For more information, see OCSP Response Cache Server (in this topic).
Note that the JVM options should be set on launch, and not programmatically (via System.setProperty()). If both environment variable and JVM options are provided, the JVM option will be used.
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:
- Java Core Logging Facilities (default logger for the driver)
- Simple Logging Facade for Java
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.
Starting with version 3.0.4, the JDBC driver supports the following logging frameworks:
- Java Core Logging Facilities (default logger for the driver)
- Simple Logging Facade for Java
- Logging Configuration File
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:
OFFSEVEREWARNINGINFOCONFIGFINEFINERFINESTALL
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:
Specify the JVM parameters before the -jar option on the command line:
Where application.jar references the application code for the JDBC driver. The log files are located in /tmp/snowflake_jdbc*.
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 or connection property to true, which writes all logs to the standard output stream. The default value is false.
If you enable JAVA_LOGGING_CONSOLE_STD_OUT, you can also set the JAVA_LOGGING_CONSOLE_STD_OUT_THRESHOLD java or connection 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:
OFFSEVEREWARNINGINFOCONFIGFINEFINERFINESTALL
To choose this logger 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:
Specify the JVM parameters in the command line:
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-apiand its implementation (for example,logback) to theclasspath. The JDBC Driver 5.x packages don’t includeslf4j-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:
DEBUGERRORINFOOFFTRACEWARNING
This configuration file uses JSON to define the log_level and log_path logging parameters, as follows:
The driver looks configuration details in the following order:
-
client_config_fileconnection parameter, containing the full path to the user-defined logging configuration file. For example: -
SF_CLIENT_CONFIG_FILEenvironment variable, containing the full path to the user-defined logging configuration file. -
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_fileconnection parameter orSF_CLIENT_CONFIG_FILEenvironment 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:
- Set the JDBC_ENABLE_PUT_GET server parameter to
FALSE. - Set the JDBC enablePutGet connection parameter to
false.
- Set the JDBC_ENABLE_PUT_GET server parameter to
FALSE. - Set the JDBC enablePutGet connection parameter to
false. - Call the
SFBaseSession.setEnablePutGet(false)method.
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(), thennewHeaders()(respectinginvokeOnce()for retries). - Customizers cannot override essential driver-set headers. This is enforced by the driver.
- Keep
applies()andnewHeaders()efficient.
The following example shows how to implement net.snowflake.client.jdbc.HttpHeadersCustomizer.
The following examples show different ways to register customizers:
-
Via
net.snowflake.client.jdbc.SnowflakeBasicDataSource: -
Via
java.sql.DriverManager:
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.