JDBC driver#
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.
Requirements#
The Trino JDBC driver has the following requirements:
Java version 8 or higher.
All users that connect to Trino with the JDBC driver must be granted access to query tables in the
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.
Installing#
Download trino-jdbc-448.jar 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>448</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.
The CLI uses the HTTP protocol and the Trino client REST API to communicate with Trino.
Registering and configuring 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.
Connecting#
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 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.
Connection parameters#
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.
Parameter reference#
Name |
Description |
---|---|
|
Username to use for authentication and authorization. |
|
Password to use for LDAP authentication. |
|
Session username override, used for impersonation. |
|
SOCKS proxy host and port. Example: |
|
HTTP proxy host and port. Example: |
|
Extra information about the client. |
|
Client tags for selecting resource groups. Example: |
|
Trace token for correlating requests across systems. |
|
Source name for the Trino query. This parameter should be used in preference
to |
|
Prefix to append to any specified |
|
JWT access token for token based authentication. |
|
Set |
|
The method of TLS verification. There are three modes: |
|
Use only when connecting to a Trino cluster that has certificate authentication enabled. Specifies the path to a PEM or JKS file, which must contain a certificate that is trusted by the Trino cluster you connect to. |
|
The password for the KeyStore, if any. |
|
The type of the KeyStore. The default type is provided by the Java
|
|
The location of the Java TrustStore file to use to validate HTTPS server certificates. |
|
The password for the TrustStore. |
|
The type of the TrustStore. The default type is provided by the Java
|
|
Set |
|
Expected hostname in the certificate presented by the Trino server. Only applicable with full SSL verification enabled. |
|
Trino coordinator Kerberos service name. This parameter is required for Kerberos authentication. |
|
The principal to use when authenticating to the Trino coordinator. |
|
Use the canonical hostname of the Trino coordinator for the Kerberos service principal by first resolving the hostname to an IP address and then doing a reverse DNS lookup for that IP address. This is enabled by default. |
|
Trino coordinator Kerberos service principal pattern. The default is
|
|
Kerberos configuration file. |
|
Kerberos keytab file. |
|
Kerberos credential cache. |
|
Set to |
|
Extra credentials for connecting to external services, specified as a list
of key-value pairs. For example, |
|
Authorization roles to use for catalogs, specified as a list of key-value
pairs for the catalog and role. For example, |
|
Session properties to set for the system and for catalogs, specified as a
list of key-value pairs. For example, |
|
Set to true if you want to use external authentication via OAuth 2.0 authentication. Use a local web browser to authenticate with an identity provider (IdP) that has been configured for the Trino coordinator. |
|
Allows the sharing of external authentication tokens between different
connections for the same authenticated user until the cache is invalidated,
such as when a client is restarted or when the classloader reloads the JDBC
driver. This is disabled by default, with a value of |
|
Whether compression should be enabled. |
|
When enabled, the name patterns passed to |
|
Sets the time zone for the session using the time zone passed. Defaults to the timezone of the JVM running the JDBC driver. |
|
Defaults to |