Support Questions
Find answers, ask questions, and share your expertise
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Java Hive client Kerberos connection issue


Java Hive client Kerberos connection issue

Expert Contributor

HDP- using Ambari and having 1.8.0_111 on my desktop.

Using the MIT Ticket Kerberos Mgr., I generated a keytab file on my Windows viz. E:\\ojoqcu.keytab. I am able to connect and query the Hive databases from SQL Developer, also, I can log-in to any of nodes and connect to beeline using the jdbc string used in the code.

I read some good existing threads like this and proceeded with the Java client(executed via Eclipse) to connect to the Hive db, following is the code :

private Connection getHiveConnection() {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("", "Kerberos");
Connection con = null;
try {
"ojoqcu@GLOBAL.SCD.COM", "E:\\ojoqcu.keytab");
//System.setProperty("", "krb5.conf");"getting connection");
con = DriverManager.getConnection("jdbc:hive2://,,;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2");

} catch (IOException e) {
logger.error("IOException in getHiveConnection()", e);
} catch (SQLException e) {
logger.error("SQLException in getHiveConnection()", e);
} catch (ClassNotFoundException e) {
logger.error("ClassNotFoundException in getHiveConnection()", e);
return con;

I get the following Exception :

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See for more info.
[ERROR] 2016-10-21 09:21:27.003 [main] HiveClient - IOException in getHiveConnection() Login failure for ojoqcu@GLOBAL.SCD.COM from keytab E:\ojoqcu.keytab: Unable to obtain password from user
at ~[hadoop-common-]
at com.hadoop.client.hive.HiveClient.getHiveConnection( [bin/:?]
at com.hadoop.client.hive.HiveClient.main( [bin/:?]
Caused by: Unable to obtain password from user
at ~[?:1.8.0_71]
at ~[?:1.8.0_71]
at ~[?:1.8.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_71]
at java.lang.reflect.Method.invoke( ~[?:1.8.0_71]
at ~[?:1.8.0_71]
at$000( ~[?:1.8.0_71]
at$ ~[?:1.8.0_71]
at$ ~[?:1.8.0_71]
at Method) ~[?:1.8.0_71]
at ~[?:1.8.0_71]
at ~[?:1.8.0_71]
at ~[hadoop-common-]
... 2 more

What am I missing :

  1. If Zookeeper service discovery is used, is it essential to use a 'principal' in the JDBC string ?
  2. Do I have to set any more system properties to ensure that the java security module works properly ?

Re: Java Hive client Kerberos connection issue

Cloudera Employee

Use this link to connect kerberos hive in JDBC.

Don't have an account?
Coming from Hortonworks? Activate your account here