我需要使用jdbc连接配置单元(kerberos + SSL),我尝试了此代码,但得到了如下错误:
线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / hadoop / util / VersionInfo 在org.apache.hadoop.hive.shims.ShimLoader.getMajorVersion(ShimLoader.java:155) 在org.apache.hadoop.hive.shims.ShimLoader.loadShims(ShimLoader.java:134) 在org.apache.hadoop.hive.shims.ShimLoader.getHadoopThriftAuthBridge(ShimLoader.java:120) 在org.apache.hive.service.auth.HttpAuthUtils.getKerberosServiceTicket(HttpAuthUtils.java:52) 在org.apache.hive.jdbc.HttpKerberosRequestInterceptor.process(HttpKerberosRequestInterceptor.java:63) 在org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109) 在org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176) 在org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:518) 在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) 在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:827) 在org.apache.thrift.transport.THttpClient.flushUsingHttpClient(THttpClient.java:235) 在org.apache.thrift.transport.THttpClient.flush(THttpClient.java:297) 在org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:65) 在org.apache.hive.service.cli.thrift.TCLIService $ Client.send_OpenSession(TCLIService.java:141) 在org.apache.hive.service.cli.thrift.TCLIService $ Client.OpenSession(TCLIService.java:133) 在org.apache.hive.jdbc.HiveConnection.createHttpTransport(HiveConnection.java:267) 在org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:201) 在org.apache.hive.jdbc.HiveConnection。(HiveConnection.java:168) 在org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105) 在java.sql.DriverManager.getConnection(DriverManager.java:664) 在java.sql.DriverManager.getConnection(DriverManager.java:270) 在prodhive.main(prod_test.java:25) 引起原因:java.lang.ClassNotFoundException:org.apache.hadoop.util.VersionInfo
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
System.out.println("Driver Registered");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("Exception Occured");
System.exit(1);
}
System.out.println("before connection");
Connection con = DriverManager.getConnection(
("jdbc:hive2://abc.xyz.com:10000/default;principal=hive/_HOST@XYZ.COM;KrbRealm=PQR.COM;KrbHostFQDN=abc.xyz.com;KrbServiceName=hive;KrbAuthType=0;SSLKeyStore=/home/arcosadmin/va.xyz.com.jks;SSLKeyStorePwd=1234;transportMode=http;httpPath=cliservice;SSL=1;AuthMech=3;UID=HS2;PWD=1234")
System.out.println("Connection Established Successfully");
Statement stmt = con.createStatement();
System.out.println("Table Creation Started");
String tableName = "hive_con";
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + "(eid int, name String,destination String)");
System.out.println("Table have been created");
con.close();
System.out.println("Connection Closed");
}