All Products
Search
Document Center

E-MapReduce:Connect to Kyuubi

Last Updated:Mar 26, 2026

Connect to Kyuubi from a command-line client using Beeline, or from a Java application using a Java Database Connectivity (JDBC) driver.

Prerequisites

Before you begin, ensure that you have:

Connect using Beeline

EMR clusters include kyuubi-beeline, the Kyuubi Beeline client. You can also use Hive Beeline. The following examples use kyuubi-beeline.

Two connection methods are available: ZooKeeper-based service discovery and direct connection. ZooKeeper-based discovery is recommended for high availability.

Common clusters

ZooKeeper (recommended)

kyuubi-beeline -n user1 \
  -u "jdbc:hive2://master-1-1:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi"
ParameterDescription
master-1-1:2181ZooKeeper host and port
serviceDiscoveryMode=zooKeeperEnables ZooKeeper-based service discovery
zooKeeperNamespace=kyuubiZooKeeper path where Kyuubi registers its instances

Direct connection

kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/"

To submit a SQL file instead of opening an interactive session:

kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/" -f query1.sql

High-security clusters

High-security clusters use Kerberos authentication. Before connecting, run kinit to obtain a ticket-granting ticket (TGT) from the Kerberos Key Distribution Center (KDC). The Beeline client uses this TGT to authenticate with Kyuubi. For Kerberos setup details, see Basic operations on Kerberos.

ZooKeeper (recommended)

kyuubi-beeline -n user1 \
  -u "jdbc:hive2://master-1-1:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=kyuubi/_HOST@EMR"

Direct connection

kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/;principal=kyuubi/_HOST@EMR"

The principal=kyuubi/_HOST@EMR parameter specifies the Kerberos service principal for the Kyuubi server.

Connect using a JDBC driver

To connect a Java application to Kyuubi, follow these steps:

  1. Add the Hive JDBC dependency to your Maven project.

  2. Build the JDBC connection URL for your cluster type.

  3. Load the driver and run a query.

Step 1: Add the Maven dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>2.3.9</version>
</dependency>

Step 2: Build the JDBC URL

The JDBC URL format is:

jdbc:hive2://<host>:<port>/<database>[;<properties>]
Cluster typeJDBC URL
Common clusterjdbc:hive2://master-1-1:10009/default;
High-security clusterjdbc:hive2://master-1-1:10009/default;principal=kyuubi/_HOST@EMR

Step 3: Load the driver and run a query

All examples use org.apache.hive.jdbc.HiveDriver as the driver class.

Common clusters

import java.sql.*;

public class JDBCTest {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String kyuubiJdbcUrl = "jdbc:hive2://master-1-1:10009/default;";

    public static void main(String[] args) throws Exception {
        Class.forName(driverName);
        // Open a connection and run a query
        try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
             Statement st = conn.createStatement();
             ResultSet res = st.executeQuery("show databases")) {
            while (res.next()) {
                System.out.println(res.getString(1));
            }
        }
    }
}

High-security clusters

Before running the application, run kinit to authenticate with Kerberos.

import java.sql.*;

public class JDBCTest {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String kyuubiJdbcUrl = "jdbc:hive2://master-1-1:10009/default;principal=kyuubi/_HOST@EMR";

    public static void main(String[] args) throws Exception {
        Class.forName(driverName);
        // Open a connection and run a query
        try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
             Statement st = conn.createStatement();
             ResultSet res = st.executeQuery("show databases")) {
            while (res.next()) {
                System.out.println(res.getString(1));
            }
        }
    }
}

References