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
A Presto cluster is created on the EMR on ACK page of the new E-MapReduce (EMR) console. For more information, see Getting Started.
The AliyunOSSFullAccess and AliyunDLFFullAccess policies are attached to your account. For more information, see Grant permissions to a role.
The password of the admin user of your Presto cluster is configured. For more information, see Configure the administrator password of a Presto cluster.
Procedure
URL: You can obtain the URL that is used to access the Trino web UI on the Access Links and Ports tab. Then, changetrinoin the URL totrino-cli.Username and password: The default username
adminand the password that you configured for the user are used.
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>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(); } }