메뉴 건너뛰기

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.
 
번호 제목 날짜 조회 수
342 hue.axes_accessattempt테이블의 username컬럼에 NULL 혹은 space가 들어갈수도 있음. 2021.11.03 3474
341 Query Status: Sender xxx.xxx.xxx.xxx timed out waiting for receiver fragment instance: 1234:cdsf, dest node: 10 의 오류 원인및 대응방안 2021.11.03 1210
340 hive metastore db중 TBLS, TABLE_PARAMS테이블 설명 2021.10.22 1102
339 kudu hms check 사용법(예시) 2021.10.22 1250
338 Hue Load Balancer를 L4로 L/B하는 경우는 L4쪽 도멘인으로 발행된 인증서를 TLS/SSL항목에 설정해주어야 한다. 2021.10.08 999
337 TLS/SSl설정시 방법및 참고 사항 2021.10.08 1089
336 you are accessing a non-optimized hue please switch to one of the available addresses 2021.10.06 1472
335 CM의 Impala->Query tab에서 FINISHED query가 보이지 않는 현상 2021.08.31 680
334 tablet별 disk사용량 확인하는 방법 2021.08.27 915
333 AnalysisException: Incomplatible return type 'DECIMAL(38,0)' and 'DECIMAL(38,5)' of exprs가 발생시 조치 2021.07.26 1447
332 drop table로 삭제했으나 tablet server에는 여전히 존재하는 테이블 삭제방법 2021.07.09 8225
331 impala session type별 표시되는 정보로 구분하는 방법 2021.05.25 953
» Hive JDBC Connection과 유형별 에러및 필요한 jar파일 2021.05.24 1054
329 [Kudu] tablet server 혹은 kudu master가 어떤 원인에 의해서 replica가 failed상태인 경우 복구하는 방법 2021.05.24 1353
328 impald에서 idle_query_timeout 와 idle_session_timeout 구분 2021.05.20 2192
327 missing block및 관련 파일명 찾는 명령어 2021.02.20 469
326 [sap] Error: java.io.IOException: SQLException in nextKeyValue 오류 발생 2020.06.08 1302
325 [kudu]테이블 drop이 안되고 timeout이 걸리는 경우 조치 방법 2020.06.08 1056
324 [oozie] oozie shell action에서 shellscript수행결과의 2개 변수를 decision 액션에서 사용하기 2020.06.05 910
323 [Sentry]HDFS의 ACL을 Sentry와 연동후 테스트 2020.06.02 1267
위로