Community Articles

Find and share helpful community-sourced technical articles.
Labels (1)

Steps to connect from a client machine (MAC in this case) to Hadoop cluster using hive JDBC.

Here are couple of links that i have used to build this out Link that talks about hive drivers and jar files

Link that talks about how to setup java jdbc setup for hive jar files

1.Here are the jar files you need to connect to HS2 For HDP 2.3

You'll only need 2 jar files for the JDBC Client

with HDP 2.3 # From

/usr/hdp/current/hive-client hive-jdbc.jar (should be a symlink to the hive-jdbc-xxx-standalone.jar)

# From /usr/hdp/current/hadoop-client hadoop-common.jar (hadoop-common-....jar)

2. Make sure that java home is set on your machine

This is value that i have on my machine for JAVA_HOME



3. Move these jar files to java library directory on my machine


4. Set the java classpath for the hive jar file

export CLASSPATH=$CLASSPATH:/Library/Java/Extensions/hive-jdbc.jar

5. Use any java based IDE (I used eclipse) to write a simple java class to connect to hiver server2.

Where the jdbc string is mentioned, you have to specify the hive server that you are using and corresponding userid and password as well

Here is the code for that

package hive_test;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClientv1 {
  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://", "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 + "'";
    String sql = ("show tables");
    ResultSet res = stmt.executeQuery(sql);
    if ( {

Hi @Chakra,

After adding all the jars mentioned by you, to build path and executing the program getting error as follows :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException at org.apache.hive.jdbc.HiveDriver.connect( at java.sql.DriverManager.getConnection( at java.sql.DriverManager.getConnection( at edu.thenet.pc1.connect.hive.HiveJdbcConnector.main( Caused by: java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransportException at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( ... 4 more

Can you please help me to identify which other jars are also required ?

Thank you,


Not applicable

Hello Chakra!!

What jar files need to be added for windows machine or Linux?

I am on HDP 2.5, Hive, Beeline 1.2

Please see my question here on SOF,

Please let me know. Thanks in advance!!

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.
Version history
Last update:
‎03-31-2016 11:20 PM
Updated by:
Top Kudoed Authors