Connect to Trino via JDBC

Overview

The Trino service supports user access from Java applications using the JDBC driver. It uses the client protocol over HTTP/HTTPS to connect to the Trino Coordinator component.

Installation

Before the installation of the JDBC driver make sure the following prerequisites are met:

  1. Java runtime environment (JRE) version 8 or higher is installed. JRE version 22 or higher is recommended.

  2. Users that are supposed to connect to Trino must have access to query tables, which is defined in the system.jdbc schema.

  3. The Trino Coordinator component is network accessible.

Some client applications already have a built-in Trino JDBC driver. If yours does not, download the driver file. The link to the most recent file is available at the Trino documentation website or at Maven central repository. Add the downloaded file to the directory in the users classpath on the machines that are supposed to connect to Trino, and restart the client application. You may probably have to manually register the Trino JDBC driver in the client application: some of them do it automatically, some do not. Refer to the documentation of your client application for assistance.

Usage

Connection

After the Trino JDBC driver has been registered and configured in your client application, you can connect to Trino. Use the following JDBC URL formats:

jdbc:trino://<host>:<port>
jdbc:trino://<host>:<port>/<catalog>
jdbc:trino://<host>:<port>/<catalog>/<schema>

where:

  • <host> is the network address of the Trino Coordinator component node;

  • <port> is the listening port of the Trino Coordinator component (18188 by default);

  • <catalog> is the name of the Trino catalog to use;

  • <schema> is the name of the DB or schema to connect to.

Connection parameters

You can define additional connection parameters as URL parameters or as properties passed to the DriverManager class. For example, you may want to connect to Trino using the following parameters:

  • network address and port — myorganization.org:18188;

  • catalog and schema — hive/tech;

  • user — admin;

  • password — MySecretPassword1984.

In this case, you will need to use the following URL parameters:

String mycustomurl = "jdbc:trino://myorganization.org:18188/hive/tech?user=admin&password=MySecretPassword1984";
Connection connection = DriverManager.getConnection(mycustomurl);

Or if you want to pass the parameters to DriverManager, you will need to define the following properties:

String url = "jdbc:trino://myorganization.org:18188/hive/tech";
Properties mycustomproperties = new Properties();
mycustomproperties.setProperty("user", "admin");
mycustomproperties.setProperty("password", "MySecretPassword1984");
Connection connection = DriverManager.getConnection(url, mycustomproperties);

You can use a combination of these approaches, but overlapping of the parameters is prohibited: a parameter defined by one method cannot be defined by the other.

List of available parameters is provided on the JDBC driver page of the Trino documentation.

Found a mistake? Seleсt text and press Ctrl+Enter to report it