gpt4 book ai didi

java - 使用 JDBC 和 Kerberos 身份验证连接到 Hive 时出现异常

转载 作者:可可西里 更新时间:2023-11-01 16:28:28 29 4
gpt4 key购买 nike

我正在尝试使用 Java 中的 JDBC 和 Kerberos 身份验证连接到 Hive。为此,我想出了以下代码。

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;

public class DbManager {
private static Connection hiveConnection;
// get Hive Connection
public static Connection qwtHiveConnection() throws IOException, SQLException {

System.out.println("Preparing Hive connection1");
Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("username@HLC.ABC.QW.COM", "path of keytab");
// Hive Connection
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
if(hiveConnection == null) {
hiveConnection = DriverManager.getConnection("jdbc:hive2://abcd1dq000.hlc.abc.qw.com:10000/finance;principal=hive/_HOST@HLC.ABC.QW.COM", "usrname", "pwd");
return hiveConnection;
} else {
return hiveConnection;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}

我从命令“hadoop 版本”中看到的 Hadoop 版本: Hadoop 2.7.3.2.6.2.0-205 此命令使用/usr/hdp/2.6.2.0-205/hadoop/hadoop-common-2.7.3.2.6.2.0-205.jar 运行

我在项目中使用了以下 jar 文件:

hive-jdbc-2.2.0.jar,
postgresql-9.4.1212.jar,
apache-commons.jar,
slf4j-api-1.7.25.jar,
hadoop-commons-2.6.2.jar,
guava-18.0.jar,
commons-configuration-1.9.jar,
commons-lang-2.6.jar,
hadoop-auth-2.6.2.jar,
hadoop-core-1.2.0.jar

当我运行 jar 时,出现异常:

Preparing Hive connection1
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.
Kerberos Connected
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hive/service/rpc/thrift/TCLIService$Iface
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.dbconnections.gphive.DbManager.getHiveConnection(DbManager.java:35)
at com.recordcount.dao.GpHiveRecords.getHiveTableCount(GpHiveRecords.java:93)
at com.recordcount.entry.StartCount.main(StartCount.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.hive.service.rpc.thrift.TCLIService$Iface
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more

最佳答案

看起来您错过了以下依赖项:

<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service-rpc</artifactId>
<version>2.2.0</version>
</dependency>

此 jar 包含缺少的接口(interface)。

更新:

看起来你还需要:

<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>2.2.0</version>
</dependency>

还有我的其他 jar 。

关于java - 使用 JDBC 和 Kerberos 身份验证连接到 Hive 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49252951/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com