tencent cloud

Feedback

Presto JDBC Access

Last updated: 2024-09-04 11:16:59

    Supported Engine Types

    Standard Presto Engine

    Environment Preparation

    Dependency: JDK 1.8
    Note:
    Currently, only the Standard Presto Engine supports access using the Presto JDBC. If you are using the SuperSQL Engine, see the DLC JDBC Access.

    Connecting to the Standard Presto Engine

    Creating a Service Access Link

    Go to the Standard engine page, and click the Details button for the gateway to enter the gateway details page.
    
    Click Create Private Link, select the VPC and subnet where the submission machine is located, and click Create. This will generate two access links, one for the Hive2 protocol and one for the Presto protocol. Use the Presto protocol to connect to the Standard Presto Engine, as shown in the diagram below.
    Note:
    Creating a private connection will establish a network link between the engine network and the selected VPC. The submission machine can be any server within the selected VPC that is accessible and used solely for task submission. If there is no submission machine available in the selected VPC, you can create a new server to serve as the submission machine.
    
    jdbc:presto://{endpoint}:10999/?sessionProperties=presto.engine:{DataEngineName};region:{Region};database:{DatabaseName};catalog:{Catalog}&extraCredentials=secretkey:{SecretKey};secretid:{SecretId}

    Loading the JDBC Driver

    Class.forName("com.facebook.presto.jdbc.PrestoDriver");

    Creating a Connection Using DriverManager

    String url = "jdbc:presto://{endpoint}:10999/?sessionProperties=presto.engine:{DataEngineName};region:{Region};database:{DatabaseName};catalog:{Catalog}&extraCredentials=secretkey:{SecretKey};secretid:{SecretId}";
    Properties properties = new Properties();
    properties.setProperty("user", {AppId});
    Connection connection = DriverManager.getConnection(url, properties);

    JDBC Connection String Parameter Descriptions

    Parameter
    Required
    Description
    presto.engine
    Yes
    The name of the Standard Presto Engine
    database
    Yes
    The name of the database
    secretkey
    Yes
    The SecretKey from Tencent Cloud API Key Management
    secretid
    Yes
    The SecretId from Tencent Cloud API Key Management.
    region
    Yes
    The region. Currently, DLC services support the following: ap-nanjing, ap-beijing, ap-beijing-fsi, ap-guangzhou, ap-shanghai, ap-chengdu, ap-chongqing, na-siliconvalley, ap-singapore, ap-hongkong, na-ashburn, eu-frankfurt and ap-shanghai-fsi.
    catalog
    Yes
    The name of the data catalog
    extraCredentials
    Yes
    SecretKey: The SecretKey from Tencent Cloud API Key Management
    SecretId: The SecretId from Tencent Cloud API Key Management
    user
    Yes
    The user's APPID

    Complete Example of Data Query

    import com.facebook.presto.jdbc.PrestoStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Properties;
    
    public class TestJDBCKyuubiPresto {
    public static void main(String[] args) throws SQLException {
    try {
    Class.forName("com.facebook.presto.jdbc.PrestoDriver");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    return;
    }
    String url = "jdbc:presto://{endpoint}:10999/?sessionProperties=presto.engine:{DataEngineName};region:{Region};database:{DatabaseName};catalog:{Catalog}&extraCredentials=secretkey:{SecretKey};secretid:{SecretId}";
    Properties properties = new Properties();
    properties.setProperty("user", {AppId});
    Connection connection = DriverManager.getConnection(url, properties);
    PrestoStatement statement = (PrestoStatement) connection.createStatement();
    String sql = "show catalogs";
    statement.execute(sql);
    ResultSet rs = statement.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getString(1));
    }
    rs.close();
    statement.close();
    connection.close();
    }
    After compilation is completed, you can upload the JAR file to the submission machine for execution.
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support