JDBC 驱动

Trino JDBC 驱动

qianmoQqianmoQ· 更新于 2026-09-29· 阅读 3 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

使用说明

Kyuubi 目前支持 Trino 连接协议,因此我们可以使用 Trino-JDBC 连接到 Kyuubi 服务器,并向 Spark、Trino 等引擎提交 SQL 执行。

启动 Kyuubi Trino Server

首先,我们需要在 kyuubi.conf 中配置 trino 协议和服务端口。

kyuubi.frontend.protocols TRINO
kyuubi.frontend.trino.bind.port 10999 #default port

安装 Trino JDBC

下载 trino-jdbc-411.jar 并将其添加到你的 Java 应用程序的 classpath 中。

该驱动也可以从 Maven Central 获取:

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

JDBC URL

当驱动程序加载、注册并配置完成后,即可从应用程序连接到 Trino。支持以下 JDBC URL 格式:

jdbc:trino://host:port

Trino JDBC 示例

String trinoHost = "localhost";
String trinoPort = "10999";
String trinoUser = "default";
String trinoPassword = null;
Connection connection = null;
ResultSet rs = null;

try {
    // Create the connection using the JDBC URL
    connection = DriverManager.getConnection("jdbc:trino://" + trinoHost + ":" + trinoPort, trinoUser, trinoPassword);

    // Do whatever you need to do with the connection
    Statement stmt = connection.createStatement();
    rs = stmt.executeQuery("SELECT 1");

    while (rs.next()) {
    // retrieve data from the ResultSet
    }

} catch (Exception e) {
    e.printStackTrace();
} finally {
    try {
        // Close the connection when you're done with it
        if (rs != null) rs.close();
        if (connection != null) connection.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

连接参数的配置可以在 Trino 官方文档中找到:https://trino.io/docs/current/client/jdbc.html#connection-parameters

评论

登录后参与评论

正在加载评论…