메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


Hive JDBC Connection And JAR file errors
Required jar file

JAR FILE     PATH
a.  hive-jdbc.jar               /usr/lib/hive/lib
b.  hive-service                /usr/lib/hive/lib
c.  libthrift-0.9.2             /usr/lib/hive/lib
d.  commons-logging            /usr/lib/hive/lib
e.  httpclient-4.2.5            /usr/lib/hive/lib
f.  httpcore                   /usr/lib/hive/lib
g.  hive-common                /usr/lib/hive/lib
h.  hive-metastore.jar          /usr/lib/hive/lib
i.  hadoop-common              /usr/lib/hadoop/client-0.20
j.  slf4j-api                  /usr/lib/hadoop/client
k.  log4j                      /usr/lib/hadoop/lib
l.  slf4j-log4j                /usr/lib/hadoop/lib

 Download above JAR file from above listed directory in cloudvm 


 start beeline
# beeline -u jdbc:hive2://192.168.11.136:10000/default -n admin -d org.apache.hive.jdbc.HiveDriver
#  hive --service hiveserver2

Verify hiveserver2 running status
# netstat -nl |grep 10000



If your hive2 is not starting then delete below files from given directory 
* Delete  : /var/lib/hive/metastore/metastore_db   (.lck file) if  hiveserver2 not started


 
 
Connect to beeline
 
 
beeline -u jdbc:hive2://192.168.11.136:10000/default -n admin -d org.apache.hive.jdbc.HiveDriver
 
 
or
 
 
·          
Example
% bin/beeline
Hive version 0.11.0-SNAPSHOT by Apache
beeline> !connect jdbc:hive2://localhost:10000 scott tiger org.apache.hive.jdbc.HiveDriver
 
 
 
 
Program
 
 
package com.kshitish.dbcon;
 
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
/**
* hive2 connection
* start beeline
* command : beeline -u jdbc:hive2://192.168.11.136:10000/default -n admin -d org.apache.hive.jdbc.HiveDriver
* command :  hive --service hiveserver2
* command : netstat -nl |grep 10000
* Delete  : /var/lib/hive/metastore/metastore_db   (.lck file) if  hiveserver2 not started
*
 * add jar from below directory  /usr/lib
 *
 * -----> hive
* -----> hadoop-mapreduce
* -----> hadoop-0.20-mapreduce
* -----> hadoop
*
 * @author k.a.chandra.pradhan
*
*/
public class HiveJdbcClient {
 
       private static String driverName = "org.apache.hive.jdbc.HiveDriver";
 
       public static void main(String[] args) throws SQLException {
              try {
                     Class.forName(driverName);
              } catch (ClassNotFoundException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                     System.out.println("Got some exception");
                     System.exit(1);
              }
 
 
 
              System.out.println("before connection");
              Connection con = DriverManager.getConnection("jdbc:hive2://192.168.11.136:10000/ksh", "", "");
              System.out.println("after connection stage");
              Statement stmt = con.createStatement();
              System.out.println("after connection");
 
              String tableName = "kshitish_storage";
              stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " +tableName + "(eid int, name String,salary String, destination String)");
              System.out.println("Table have been created");
             
              String sql = "show tables '" + tableName + "'";
              System.out.println("Running: " + sql);
             
              Statement stmt1 = con.createStatement();
              ResultSet rs = stmt1.executeQuery("describe kshitish_storage");
 
              while (rs.next())
              {
                     System.out.println(rs.getString(1) + ":" + rs.getString(2) );
              }
              rs.close();
       }
}
 




Possibility of errors during Hive Connection due to JAR file 

ERROR WITH JARS
 
 
hive-service jar file   in /usr/lib/hive/lib   
 
issues
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hive/service/cli/thrift/TCLIService$Iface
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.hive.service.cli.thrift.TCLIService$Iface
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
      
       =====================================================================
hive-jdbc.jar      in /usr/lib/hive/lib 
 
issues
      
       java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:32)
      
====================================================================================
libthrift           in     /usr/libhive/lib
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransportException
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 4 more
      
====================================================================================================
commons-logging jar      in /usr/libhive/lib
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
       at org.apache.hive.jdbc.HiveConnection.<clinit>(HiveConnection.java:94)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 5 more   
      
==============================================================================================
httpclient-4.2.5      in   /usr/lib/hive/lib
 
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)    
      
      
================================================================================================
httpcore                          in                                /usr/lib/hive/lib
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequestInterceptor
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 4 more
 
==================================================================================================
hive-common                in      /usr/lib/hive/lib
 
log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 7 more
 
      
=======================================================================================================
hive-metastore            in          /usr/lib/hive/lib
 
 
       log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/metastore/api/MetaException
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.metastore.api.MetaException
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 7 more
      
====================================================================================================
hadoop-common         in     /usr/lib/hadoop/client-0.20
 
log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 7 more
      
==============================================================================================
slf4j-api jar     in  /usr/lib/hadoop/client
 
 
log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
       at org.apache.hive.service.auth.HiveAuthFactory.<clinit>(HiveAuthFactory.java:63)
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 8 more
      
 
==================================================================================================
log4j                      in                                              /usr/lib/hadoop/lib
 
 
Dec 15, 2015 8:13:56 PM org.apache.hive.jdbc.Utils parseURL
INFO: Supplied authorities: 192.168.117.136:10000
Dec 15, 2015 8:13:56 PM org.apache.hive.jdbc.Utils parseURL
INFO: Resolved authority: 192.168.117.136:10000
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
       at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
       at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
       at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
       at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
       at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
       at org.apache.hive.service.auth.HiveAuthFactory.<clinit>(HiveAuthFactory.java:63)
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 13 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
       at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
       at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
       at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
       at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
       at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
       at org.apache.hive.service.auth.HiveAuthFactory.<clinit>(HiveAuthFactory.java:63)
       at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:402)
       at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
       at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:167)
       at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at java.sql.DriverManager.getConnection(Unknown Source)
       at HiveJdbcClientV2.main(HiveJdbcClientV2.java:43)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 13 more
 
 
====================================================================================================================
slf4j-log4j                in                                /usr/lib/hadoop/lib
 
only warning u will get but it will execute
 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
 
번호 제목 날짜 조회 수
621 Hue Load Balancer를 L4로 L/B하는 경우는 L4쪽 도멘인으로 발행된 인증서를 TLS/SSL항목에 설정해주어야 한다. 2021.10.08 929
620 TLS/SSl설정시 방법및 참고 사항 2021.10.08 1003
619 you are accessing a non-optimized hue please switch to one of the available addresses 2021.10.06 1358
618 CM의 Impala->Query tab에서 FINISHED query가 보이지 않는 현상 2021.08.31 468
617 tablet별 disk사용량 확인하는 방법 2021.08.27 882
616 AnalysisException: Incomplatible return type 'DECIMAL(38,0)' and 'DECIMAL(38,5)' of exprs가 발생시 조치 2021.07.26 1391
615 drop table로 삭제했으나 tablet server에는 여전히 존재하는 테이블 삭제방법 2021.07.09 8128
614 impala session type별 표시되는 정보로 구분하는 방법 2021.05.25 880
» Hive JDBC Connection과 유형별 에러및 필요한 jar파일 2021.05.24 1014
612 [Kudu] tablet server 혹은 kudu master가 어떤 원인에 의해서 replica가 failed상태인 경우 복구하는 방법 2021.05.24 1350
611 impald에서 idle_query_timeout 와 idle_session_timeout 구분 2021.05.20 2187
610 missing block및 관련 파일명 찾는 명령어 2021.02.20 443
609 lombok설치방법 2020.06.20 349
608 [sap] Error: java.io.IOException: SQLException in nextKeyValue 오류 발생 2020.06.08 825
607 [kudu]테이블 drop이 안되고 timeout이 걸리는 경우 조치 방법 2020.06.08 962
606 [oozie] oozie shell action에서 shellscript수행결과의 2개 변수를 decision 액션에서 사용하기 2020.06.05 879
605 [Sentry]HDFS의 ACL을 Sentry와 연동후 테스트 2020.06.02 1093
604 [sqoop] mapper를 2이상으로 설정하기 위한 split-by컬럼을 찾을때 유용하게 활용할 수 있는 쿼리 2020.05.13 1036
603 mysql sqoop작업을 위해서 mysql-connector-java.jar을 추가하는 경우 확실하게 인식시키는 방법 2020.05.11 796
602 W/F수행후 Logs not available for 1. Aggregation may not to complete. 표시되며 로그내용이 보이지 않은 경우 2020.05.08 2398
위로