All Products
Search
Document Center

E-MapReduce:Use JDBC to submit a Presto job

Last Updated:Mar 26, 2025

This topic describes how to use Java Database Connectivity (JDBC) to access Trino on ACK and perform query operations.

Background information

For more information about Trino JDBC and related parameters, see JDBC driver.

Prerequisites

Procedure

Note
  • URL: You can obtain the URL that is used to access the Trino web UI on the Access Links and Ports tab. Then, change trino in the URL to trino-cli.

  • Username and password: The default username admin and the password that you configured for the user are used.

  1. Add a dependency to the pom.xml file.

    Add the following dependency to the pom.xml file:

    <!--JDBC packages are usually backward compatible. Select the latest version of the JDBC package. -->
    <dependency>
      <groupId>io.trino</groupId>
      <artifactId>trino-jdbc</artifactId>
      <version>xxx</version>
    </dependency>
  2. Use JDBC to access Trino on ACK.

    Sample TrinoSqlConnection.java file:

    package com.alibaba.emr;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Properties;
    
    public class TrinoSqlConnection {
        public static void main(String[] args) throws SQLException {
            // The URL.
            String url = "jdbc:trino://trino-cli.c-xxx.xxx.cn-hangzhou.alicontainer.com:443";
            Properties properties = new Properties();
            // The username.
            properties.setProperty("user", "xxx");
            // The password.
            properties.setProperty("password", "xxx");
            properties.setProperty("SSL", "true");
            properties.setProperty("SSLVerification", "NONE");
            Connection connection = DriverManager.getConnection(url, properties);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("show catalogs");
            while(rs.next()){
                System.out.println(rs.getString("Catalog"));
            }
            stmt.close();
            connection.close();
        }
    }