All Products
Search
Document Center

E-MapReduce:Use JDBC to connect to Trino

Last Updated:Mar 26, 2026

Connect to a Trino database in an E-MapReduce (EMR) cluster using the Trino JDBC driver to run complex queries, analyze data, or integrate results into Java applications.

Prerequisites

Before you begin, ensure that you have:

  • An EMR cluster with the Trino service installed

  • Network access to the EMR cluster from the machine running your Java application (same VPC)

  • Maven (if using Maven to manage dependencies)

Add the JDBC driver dependency

Add the correct JDBC driver dependency to pom.xml based on your EMR cluster version.

EMR version Component version Maven dependency Driver class
EMR 3.X series: V3.38.0 and later<br>EMR 5.X series: V5.5.0 and later 3XX groupId: io.trino<br>artifactId: trino-jdbc io.trino.jdbc.TrinoDriver
EMR 3.X series: V3.25.0–V3.37.X<br>EMR 4.X series: V4.3.0–V4.9.0<br>EMR 5.X series: V5.2.1–V5.4.3 3XX groupId: io.prestosql<br>artifactId: presto-jdbc io.prestosql.jdbc.PrestoDriver
Other EMR versions 0.2XX groupId: com.facebook.presto<br>artifactId: presto-jdbc com.facebook.presto.jdbc.PrestoDriver

Example: EMR V3.38.0 and later, or V5.5.0 and later

<dependency>
    <groupId>io.trino</groupId>
    <artifactId>trino-jdbc</artifactId>
    <version>3XX</version>
</dependency>

Example: EMR V3.25.0–V3.37.X, V4.3.0–V4.9.0, or V5.2.1–V5.4.3

<dependency>
    <groupId>io.prestosql</groupId>
    <artifactId>presto-jdbc</artifactId>
    <version>3XX</version>
</dependency>

Example: Other EMR versions

<dependency>
    <groupId>com.facebook.presto</groupId>
    <artifactId>presto-jdbc</artifactId>
    <version>0.2XX</version>
</dependency>

Connect to a database

The JDBC URL format depends on your EMR cluster version.

EMR V3.38.0 and later, or V5.5.0 and later — use the jdbc:trino scheme:

jdbc:trino://<COORDINATOR>:<PORT>/[CATALOG]/[SCHEMA]

Other EMR versions — use the jdbc:presto scheme:

jdbc:presto://<COORDINATOR>:<PORT>/[CATALOG]/[SCHEMA]
Parameter Description
<COORDINATOR> Name or IP address of the master node
<PORT> Trino port number
[CATALOG] (Optional) Catalog name
[SCHEMA] (Optional) Schema name

Master node names:

  • DataLake cluster: master-1-1

  • Hadoop cluster: emr-header-1

URL examples (for EMR V3.38.0+ or V5.5.0+):

jdbc:trino://master-1-1:9090               // default catalog and schema
jdbc:trino://master-1-1:9090/hive          // catalog=hive, default schema
jdbc:trino://master-1-1:9090/hive/default  // catalog=hive, schema=default

URL examples (for other EMR versions):

jdbc:presto://master-1-1:9090               // default catalog and schema
jdbc:presto://master-1-1:9090/hive          // catalog=hive, default schema
jdbc:presto://master-1-1:9090/hive/default  // catalog=hive, schema=default
Replace master-1-1 with the actual name of the master node in your cluster. For a DataLake cluster, the master node name is master-1-1. For a Hadoop cluster, the master node name is emr-header-1.

Pass connection parameters

Pass parameters to DriverManager using either a Properties object or URL query parameters.

// Method 1: Properties object
String url = "jdbc:trino://master-1-1:9090/hive/default";
Properties properties = new Properties();
properties.setProperty("user", "hadoop");
properties.setProperty("SSL", "true");
Connection connection = DriverManager.getConnection(url, properties);

// Method 2: URL parameters
String url = "jdbc:trino://master-1-1:9090/hive/default?user=hadoop&SSL=true";
Connection connection = DriverManager.getConnection(url);
For EMR versions that use the jdbc:presto scheme, replace jdbc:trino with jdbc:presto in the examples above.

Connection parameters

Parameter Type Description
user STRING Username for authentication and authorization
password STRING Password for Lightweight Directory Access Protocol (LDAP) authentication
socksProxy STRING:NUMBER SOCKS proxy address and port. Example: localhost:1080
httpProxy STRING:NUMBER HTTP proxy address and port. Example: localhost:8888
SSL BOOLEAN Whether to enable SSL for HTTPS connections. Default: false
SSLTrustStorePath STRING Path to the Java truststore file
SSLTrustStorePassword STRING Password to access the Java truststore file
KerberosRemoteServiceName STRING Name of the Kerberos service
KerberosPrincipal STRING Name of the Kerberos principal
KerberosUseCanonicalHostname BOOLEAN Whether to use a canonical hostname. Default: false
KerberosConfigPath STRING Path to the Kerberos configuration file
KerberosKeytabPath STRING Path to the Kerberos keytab file
KerberosCredentialCachePath STRING Path to the Kerberos credential cache

Example

The following code connects to Trino, runs a query, and prints the results:

Connection connection = null;
Statement statement = null;
try {
    // JDBC URL — use jdbc:trino for EMR V3.38.0+/V5.5.0+, or jdbc:presto for other versions
    String url = "jdbc:trino://master-1-1:9090/hive/default";
    Properties properties = new Properties();
    properties.setProperty("user", "hadoop");

    // Create a connection
    connection = DriverManager.getConnection(url, properties);

    // Create a statement and run a query
    statement = connection.createStatement();
    ResultSet rs = statement.executeQuery("select * from t1");

    // Print results
    int columnNum = rs.getMetaData().getColumnCount();
    int rowIndex = 0;
    while (rs.next()) {
        rowIndex++;
        for (int i = 1; i <= columnNum; i++) {
            System.out.println("Row " + rowIndex + ", Column " + i + ": " + rs.getInt(i));
        }
    }
} catch (SQLException e) {
    LOG.ERROR("Exception thrown.", e);
} finally {
    // Release resources
    if (statement != null) {
        try {
            statement.close();
        } catch (Throwable t) {
            // No-ops
        }
    }
    if (connection != null) {
        try {
            connection.close();
        } catch (Throwable t) {
            // No-ops
        }
    }
}

FAQ

When connecting via JDBC, I get the error `Authentication failed: Basic authentication or X-Trino-User must be sent`. What should I do?

This error occurs when the JDBC driver version does not match the Trino version running on your cluster. Use the driver that corresponds to your EMR cluster version — refer to the dependency table to select the correct groupId, artifactId, and version.

What's next

For simple, ad hoc queries, connect to Trino using the CLI instead. See Use the CLI to connect to Trino.