메뉴 건너뛰기

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.
 
번호 제목 날짜 조회 수
47 [CDP7.1.7, Hive Replication]Hive Replication진행중 "The following columns have types incompatible with the existing columns in their respective positions " 오류 2023.12.27 389
46 hive의 메타정보 테이블을 MariaDB로 사용하는 경우 table comment나 column comment에 한글 입력시 깨지는 경우 utf8로 바꾸는 방법. 2023.03.10 1501
45 [hive] hive.tbls테이블의 owner컬럼값은 hadoop.security.auth_to_local에 의해서 filtering된다. 2022.04.14 660
44 hive metastore db중 TBLS, TABLE_PARAMS테이블 설명 2021.10.22 1059
43 impala session type별 표시되는 정보로 구분하는 방법 2021.05.25 909
» Hive JDBC Connection과 유형별 에러및 필요한 jar파일 2021.05.24 1040
41 hive metadata(hive, impala, kudu 정보가 있음) 테이블에서 db, table, owner, location를 조회하는 쿼리 2020.02.07 1097
40 hive테이블의 물리적인 위치인 HDFS에 여러개의 데이터 파일이 존재할때 한개의 파일로 merge하여 동일한 테이블에 입력하는 방법 2019.05.23 1315
39 json으로 존재하는 데이터 parsing하기 2019.03.25 1696
38 [sentry]role부여후 테이블명이 변경되어 오류가 발생할때 조치방법 2018.10.16 1017
37 hive metastore ERD file 2018.09.20 989
36 oracle to hive data type정리표 2018.08.22 5146
35 upsert구현방법(년-월-일 파티션을 기준으로) 및 테스트 script file 2018.07.03 2115
34 beeline으로 접근시 "User: gooper is not allowed to impersonate anonymous (state=08S01,code=0)"가 발생하면서 "No current connection"이 발생하는 경우 조치 2018.04.15 907
33 Hive MetaStore Server기동시 Could not create "increment"/"table" value-generation container SEQUENCE_TABLE since autoCreate flags do not allow it. 오류발생시 조치사항 2017.05.03 707
32 Ubuntu 16.04 LTS에 Hive 2.1.1설치하면서 "Version information not found in metastore"발생하는 오류원인및 조치사항 2017.05.03 658
31 AIX 7.1에서 hive실행시 "hive: line 86: readlink: command not found" 오류가 발생시 임시 조치사항 2016.09.25 1000
30 hive기동시 Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D 오류 발생시 조치사항 2016.09.25 1046
29 schema설정없이 hive를 최초에 실행했을때 발생하는 오류메세지및 처리방법 2016.09.25 1381
28 beeline실행시 User: root is not allowed to impersonate오류 발생시 조치사항 2016.06.03 925
위로