docs/src/main/sphinx/client/jdbc.md
The Trino JDBC driver allows users to access Trino using Java-based applications, and other non-Java applications running in a JVM. Both desktop and server-side applications, such as those used for reporting and database development, use the JDBC driver.
The JDBC driver uses the over HTTP/HTTPS to communicate with the coordinator on the cluster.
The Trino JDBC driver has the following requirements:
system.jdbc schema.The JDBC driver version should be identical to the version of the Trino cluster, or newer. Older versions typically work, but only a subset is regularly tested. Versions before 350 are not supported.
(jdbc-installation)=
Download {download_mc}jdbc and add it to the classpath of your Java application.
The driver is also available from Maven Central:
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-jdbc</artifactId>
<version>|trino_version|</version>
</dependency>
We recommend using the latest version of the JDBC driver. A list of all
available versions can be found in the Maven Central Repository. Navigate to the
directory for the desired version, and select the trino-jdbc-xxx.jar file
to download, where xxx is the version number.
Once downloaded, you must add the JAR file to a directory in the classpath of users on systems where they will access Trino.
After you have downloaded the JDBC driver and added it to your classpath, you'll typically need to restart your application in order to recognize the new driver. Then, depending on your application, you may need to manually register and configure the driver.
Drivers are commonly loaded automatically by applications once they are added to its classpath. If your application does not, such as is the case for some GUI-based SQL editors, read this section. The steps to register the JDBC driver in a UI or on the command line depend upon the specific application you are using. Please check your application's documentation.
Once registered, you must also configure the connection information as described in the following section.
When your driver is loaded, registered and configured, you are ready to connect to Trino from your application. The following JDBC URL formats are supported:
jdbc:trino://host:port
jdbc:trino://host:port/catalog
jdbc:trino://host:port/catalog/schema
The value for port is optional if Trino is available at the default HTTP port
80 or with SSL=true and the default HTTPS port 443.
The following is an example of a JDBC URL used to create a connection:
jdbc:trino://example.net:8080/hive/sales
This example JDBC URL locates a Trino instance running on port 8080 on
example.net, with the catalog hive and the schema sales defined.
:::{note}
Typically, the JDBC driver classname is configured automatically by your
client. If it is not, use io.trino.jdbc.TrinoDriver wherever a driver
classname is required.
:::
(jdbc-java-connection)=
The driver supports various parameters that may be set as URL parameters,
or as properties passed to DriverManager. Both of the following
examples are equivalent:
// properties
String url = "jdbc:trino://example.net:8080/hive/sales";
Properties properties = new Properties();
properties.setProperty("user", "test");
properties.setProperty("password", "secret");
properties.setProperty("SSL", "true");
Connection connection = DriverManager.getConnection(url, properties);
// URL parameters
String url = "jdbc:trino://example.net:8443/hive/sales?user=test&password=secret&SSL=true";
Connection connection = DriverManager.getConnection(url);
These methods may be mixed; some parameters may be specified in the URL, while others are specified using properties. However, the same parameter may not be specified using both methods.
(jdbc-parameter-reference)=
:::{list-table} :widths: 35, 65 :header-rows: 1
userpasswordsessionUsersocksProxylocalhost:1080httpProxylocalhost:8888clientInfoclientTagsabc,xyzpathtraceTokensourceApplicationName. Thus, it takes precedence over ApplicationName
and/or applicationNamePrefix.applicationNamePrefixApplicationName client info property,
which is used to set the source name for the Trino query if the source
parameter has not been set. If neither this property nor ApplicationName
or source are set, the source name for the query is trino-jdbc.accessTokenSSLtrue to specify using TLS/HTTPS for connections.SSLVerificationFULL
(default), CA and NONE. For FULL, the normal TLS verification
is performed. For CA, only the CA is verified but hostname mismatch
is allowed. For NONE, there is no verification.SSLKeyStorePathSSLKeyStorePasswordSSLKeyStoreTypekeystore.type security property or jks if none exists.SSLUseSystemKeyStoretrue to automatically use the system KeyStore based on the operating
system. The supported OSes are Windows and macOS. For Windows, the
Windows-MY KeyStore is selected. For macOS, the KeychainStore
KeyStore is selected. For other OSes, the default Java KeyStore is loaded.
The KeyStore specification can be overridden using SSLKeyStoreType.SSLTrustStorePathSSLTrustStorePasswordSSLTrustStoreTypekeystore.type security property or jks if none exists.SSLUseSystemTrustStoretrue to automatically use the system TrustStore based on the operating
system. The supported OSes are Windows and macOS. For Windows, the
Windows-ROOT TrustStore is selected. For macOS, the KeychainStore
TrustStore is selected. For other OSes, the default Java TrustStore is
loaded. The TrustStore specification can be overridden using
SSLTrustStoreType.hostnameInCertificateKerberosRemoteServiceNameKerberosPrincipalKerberosUseCanonicalHostnameKerberosServicePrincipalPattern${SERVICE}@${HOST}. ${SERVICE} is replaced with the value of
KerberosRemoteServiceName and ${HOST} is replaced with the hostname of
the coordinator (after canonicalization if enabled).KerberosConfigPathKerberosKeytabPathKerberosCredentialCachePathKerberosDelegationtrue to use the token from an existing Kerberos context. This
allows client to use Kerberos authentication without passing the Keytab or
credential cache. Defaults to false.extraCredentialsfoo:bar;abc:xyz creates the credential
named abc with value xyz and the credential named foo with value
bar.rolescatalog1:roleA;catalog2:roleB
sets roleA for catalog1 and roleB for catalog2.sessionPropertiesabc:xyz;example.foo:bar sets the
system property abc to the value xyz and the foo property for catalog
example to the value bar.extraHeadersX-Trino-Foo:xyz;X-Trino-Bar:bar
sends the X-Trino-Foo header with the value xyz and the X-Trino-Bar
header with the value bar. Protocol headers such as X-Trino-User cannot be
overridden using this parameter.externalAuthenticationTokenCacheNONE. To enable, set
the value to MEMORY. If the JDBC driver is used in a shared mode by
different users, the first registered token is stored and authenticates all
users.disableCompressionfalse.disallowLocalRedirectfalse.assumeLiteralUnderscoreInMetadataCallsForNonConformingClientsDatabaseMetaData methods are
treated as underscores. You can use this as a workaround for applications
that do not escape schema or table names when passing them to
DatabaseMetaData methods as schema or table name patterns.timezoneexplicitPreparetrue. When set to false, prepared statements are executed
calling a single EXECUTE IMMEDIATE query instead of the standard
PREPARE <statement> followed by EXECUTE <statement>. This reduces
network overhead and uses smaller HTTP headers and requires Trino 431 or
greater.encodingjson+zstd (recommended),
JSON with LZ4 compression json+lz4, and uncompressed JSON json. By
default, the default encoding configured on the cluster is used.validateConnectionfalse. If set to true, connectivity and credentials are validated
when the connection is created, and when java.sql.Connection.isValid(int) is called.
:::(jdbc-spooling-protocol)=
The Trino JDBC driver automatically uses of the spooling protocol to improve throughput for client interactions with higher data transfer demands, if the is configured on the cluster.
Optionally use the encoding parameter to configure a different desired
encoding, compared to the default on the cluster.
The JVM process using the JDBC driver must have network access to the spooling object storage.