This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This page describes the different clients supported by HiveServer2.

Beeline - New Command Line shell

HiveServer2 supports a new command shell Beeline that works with HiveServer2. Its a JDBC client that is based on SQLLine CLI ( There’s an detailed documentation of the SQLLine which is applicable to Beeline as well. The Beeline shell works in the both embedded as well as remote mode. In the embedded mode, it runs an embedded Hive (similar to Hive CLI) where are remote mode is for connecting to a separate HiveServer2 process over Thrift.


HiveServere2 has a new JDBC driver. It supports both embedded and remote access to HiveServer2.
The JDBC connection URL format has prefix is jdbc:hive2:// and the Driver class is org.apache.hive.jdbc.HiveDriver. Note that this is different from the old hiveserver. For remote server, the URL format is jdbc:hive2://<host>:<port>/<db> (default port for HiveServer2 is 10000). For embedded server, the URL format is jdbc:hive2:// (no host or port).

JDBC Client Sample Code

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcClient {
  private static String driverName = "org.apache.hive.jdbc.HiveDriver";

 * @param args
 * @throws SQLException
  public static void main(String[] args) throws SQLException {
      try {
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
    //replace "hive" here with the name of the user the queries should run as
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "");
    Statement stmt = con.createStatement();
    String tableName = "testHiveDriverTable";
    stmt.execute("drop table if exists " + tableName);
    stmt.execute("create table " + tableName + " (key int, value string)");
    // show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    if ( {
       // describe table
    sql = "describe " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while ( {
      System.out.println(res.getString(1) + "\t" + res.getString(2));

    // load data into table
    // NOTE: filepath has to be local to the hive server
    // NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
    String filepath = "/tmp/a.txt";
    sql = "load data local inpath '" + filepath + "' into table " + tableName;
    System.out.println("Running: " + sql);

    // select * query
    sql = "select * from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while ( {
      System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));

    // regular hive query
    sql = "select count(1) from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while ( {

Running the JDBC Sample Code

# Then on the command-line
$ javac

# To run the program in standalone mode, we need the following jars in the classpath
# from hive/build/dist/lib
#     hive-exec*.jar
#     hive-jdbc*.jar
#     hive-metastore*.jar
#     hive-service*.jar
#     libfb303-0.9.0.jar#  libthrift-0.9.0.jar# log4j-1.2.16.jar# slf4j-api-1.6.1.jar# slf4j-log4j12-1.6.1.jar#
# from hadoop/build
#     hadoop-*-core.jar
# To run the program in embedded mode, we need the following additional jars in the classpath
# from hive/build/dist/lib
#     antlr-runtime-3.0.1.jar
#     derby.jar
#     jdo2-api-2.1.jar
#     jpox-core-1.2.2.jar
#     jpox-rdbms-1.2.2.jar
# as well as hive/build/dist/conf

$ java -cp $CLASSPATH HiveJdbcClient

# Alternatively, you can run the following bash script, which will seed the data file
# and build your classpath before invoking the client.


echo -e '1\x01foo' > /tmp/a.txt
echo -e '2\x01bar' >> /tmp/a.txt

HADOOP_CORE={{ls $HADOOP_HOME/hadoop-*-core.jar}}

for i in ${HIVE_HOME}/lib/*.jar ; do

java -cp $CLASSPATH HiveJdbcClient


JDBC Client Setup for a Secure Cluster

When connecting to HiveServer2 with kerberos authentication, the URL format is jdbc:hive2://<host>:<port>/<db>;principal=<Server_Principal_of_HiveServer2>. The client needs to have a valid Kerberos ticket in the ticket cache before connecting.

In case of LDAP or customer pass through authentication, the client needs to pass the valid user name and password to JDBC connection API.

  • No labels