hive jdbc 访问 配置_通过Java JDBC连接Hive

There is a question here connect from java to Hive but mine is different

My hive running on machine1 and I need to pass some queries using Java server running at machine2. As I understand Hive has a JDBC interface for the purpose of receiving remote queries. I took the code from here - HiveServer2 Clients

I installed the dependencies written in the article:

hive-jdbc*.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

commons-logging-1.0.4.jar

However I got java.lang.NoClassDefFoundError error at compile time

Full Error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration

at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:393)

at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:187)

at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:163)

at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)

at java.sql.DriverManager.getConnection(DriverManager.java:571)

at java.sql.DriverManager.getConnection(DriverManager.java:215)

at com.bidstalk.tools.RawLogsQuerySystem.HiveJdbcClient.main(HiveJdbcClient.java:25)

Another question at StackOverflow recommended to add Hadoop API dependencies in Maven - Hive Error

I don't understand why do I need hadoop API for a client to connect with Hive. Shouldn't JDBC driver be agnostic of the underlying query system? I just need to pass some SQL query?

Edit:

I am using Cloudera(5.3.1), I think I need to add CDH dependencies. Cloudera instance is running hadoop 2.5.0 and HiveServer2

But the servers are at machine 1. On machine the code should at least compile and I should have issues at runtime only!

解决方案

Answering my own question!

With some hit and trial, I have added following dependencies on my pom file and since then I am able to run code on both CHD 5.3.1 and 5.2.1 cluster.

org.apache.hive

hive-jdbc

0.13.1-cdh5.3.1

org.apache.thrift

libthrift

0.9.0

org.apache.thrift

libfb303

0.9.0

org.apache.hadoop

hadoop-core

2.5.0-mr1-cdh5.3.1

org.apache.hadoop

hadoop-common

2.5.0-cdh5.3.1

org.apache.hive

hive-exec

0.13.1-cdh5.3.1

org.apache.hadoop

hadoop-hdfs

2.5.0-cdh5.3.1

Please note that some of these dependencies might not be required

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值