<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Connecting to Kerberos-enabled hive via JDBC directly from Java in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95841#M9131</link>
    <description>&lt;P&gt;Did you try adding /etc/hive/conf, it will be the location where your hive-site.xml is? AFAIK for a single user case you should not need to do anything with UGI object. For a multi-user case, you can do something like:&lt;/P&gt;&lt;PRE&gt;UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(user, keytabfile);
Connection con = (Connection) ugi.doAs(new PrivilegedExceptionAction&amp;lt;Object&amp;gt;() {
      public Object run() {
        Connection tcon = null;
        try {
          tcon = DriverManager.getConnection(connectionURL, user, passwd);
        } catch (SQLException e) {}
        return tcon;
      }
});&lt;/PRE&gt;&lt;P&gt;Refer to &lt;A href="https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-UsingJDBC"&gt;Hive Wiki&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Oct 2015 01:17:06 GMT</pubDate>
    <dc:creator>deepesh1</dc:creator>
    <dc:date>2015-10-22T01:17:06Z</dc:date>
    <item>
      <title>Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95833#M9123</link>
      <description>&lt;P&gt;I have a Kerberos-enabled sandbox that I can connect to Hive via beeline after a kinit: !connect jdbc:hive2://localhost:10000/default;principal=hive/sandbox.hortonworks.com@EXAMPLE.COM&lt;/P&gt;&lt;P&gt;However, I need to connect directly from a Java program using the JDBC driver. A simple program fails to connect using the same URL that works for beeline above. I receive the following error: &lt;/P&gt;&lt;PRE&gt;Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default;principal=hive/sandbox.hortonworks.com@EXAMPLE.COM: GSS initiate failed
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:215)
at org.apache.hive.jdbc.HiveConnection.&amp;lt;init&amp;gt;(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:233)
at HiveJDBCTest.main(HiveJDBCTest.java:17)
Caused by: org.apache.thrift.transport.TTransportException: GSS initiate failed
at org.apache.thrift.transport.TSaslTransport.sendAndThrowMessage(TSaslTransport.java:221)
at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:297)
at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
at org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport$1.run(TUGIAssumingTransport.java:52)
at org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport$1.run(TUGIAssumingTransport.java:49)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
at org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport.open(TUGIAssumingTransport.java:49)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:190)
... 5 more&lt;/PRE&gt;&lt;P&gt;Here is the simple program I am attempting to run:&lt;/P&gt;&lt;PRE&gt;import org.apache.hive.jdbc.HiveDriver;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJDBCTest{
        public static void main(String[] args) throws SQLException{
                try {
                        Class.forName("org.apache.hive.jdbc.HiveDriver");
                } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.exit(1);
                }
                Connection cnct = DriverManager.getConnection("jdbc:hive2://localhost:10000/default;principal=hive/sandbox.hortonworks.com@EXAMPLE.COM");
                Statement stmt = cnct.createStatement();
                String sql = "show tables;";
                System.out.println("Running: " + sql);
                ResultSet res = stmt.executeQuery(sql);
                if (res.next()) {
                        System.out.println(res.getString(1));
                }
        }
}&lt;/PRE&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:02:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95833#M9123</guid>
      <dc:creator>bwilson</dc:creator>
      <dc:date>2015-10-21T23:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95834#M9124</link>
      <description>&lt;P&gt;Did you do kinit on the shell where you run the Java client from?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:06:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95834#M9124</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-10-21T23:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95835#M9125</link>
      <description>&lt;P&gt;Yup, I did. I have a ticket in the cache for the smoke user. This is the same user that I used to verify the connection with beeline. My understanding is that, like beeline, the JDBC driver should pick up my ticket from the cache without any intervention. Is that accurate?&lt;/P&gt;&lt;PRE&gt;Default principal: ambari-qa@EXAMPLE.COM
Valid starting     Expires            Service principal
10/21/15 15:48:20  10/22/15 15:48:20  krbtgt/EXAMPLE.COM@EXAMPLE.COM
renew until 10/21/15 15:48:20&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:10:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95835#M9125</guid>
      <dc:creator>bwilson</dc:creator>
      <dc:date>2015-10-21T23:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95836#M9126</link>
      <description>&lt;P&gt;its been a while, but this is at least a place to start looking at:  when you grab a connection in a kerberos mode, you need to perform the following in the connection:  &lt;/P&gt;&lt;P&gt;Subject current = Subject.getSubject(AccessController.getContext());&lt;/P&gt;&lt;P&gt;this.connection = (Connection) Subject.doAs(signedOnUserSubject, new PrivilegedExceptionAction&amp;lt;Object&amp;gt;() {&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:19:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95836#M9126</guid>
      <dc:creator>hfaouaz</dc:creator>
      <dc:date>2015-10-21T23:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95837#M9127</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/99/bwilson.html" nodeid="99"&gt;@Brandon Wilson&lt;/A&gt;&lt;P&gt;This may help  ...&lt;A target="_blank" href="http://appcrawler.com/wordpress/2015/06/18/examples-of-connecting-to-kerberos-hive-in-jdbc/"&gt;Link&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:26:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95837#M9127</guid>
      <dc:creator>nsabharwal</dc:creator>
      <dc:date>2015-10-21T23:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95838#M9128</link>
      <description>&lt;P&gt;Thanks. Java (nor the JDBC driver) does not automatically pick up the cached ticket as beeline does. I added the following based on the link provided and authenticate within the program and it works.&lt;/P&gt;&lt;PRE&gt;org.apache.hadoop.conf.Configuration conf = new     org.apache.hadoop.conf.Configuration();
                    conf.set("hadoop.security.authentication", "Kerberos");
                    UserGroupInformation.setConfiguration(conf);
                    UserGroupInformation.loginUserFromKeytab("ambari-qa@EXAMPLE.COM", "/etc/security/keytabs/smokeuser.headless.keytab");&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:37:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95838#M9128</guid>
      <dc:creator>bwilson</dc:creator>
      <dc:date>2015-10-21T23:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95839#M9129</link>
      <description>&lt;P&gt;For a single user case you may not have to do programmatic login, did you try including /etc/hive/conf in the classpath of your Java client?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2015 23:40:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95839#M9129</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-10-21T23:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95840#M9130</link>
      <description>&lt;P&gt;No dice. Adding /etc/hive/conf/* to the classpath does not help. Is there a way programmatically tell Java to grab the existing credentials from the cache?&lt;/P&gt;&lt;P&gt;**EDIT** Corrected /etc/hive/* /etc/hive/conf/*&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 00:42:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95840#M9130</guid>
      <dc:creator>bwilson</dc:creator>
      <dc:date>2015-10-22T00:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95841#M9131</link>
      <description>&lt;P&gt;Did you try adding /etc/hive/conf, it will be the location where your hive-site.xml is? AFAIK for a single user case you should not need to do anything with UGI object. For a multi-user case, you can do something like:&lt;/P&gt;&lt;PRE&gt;UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(user, keytabfile);
Connection con = (Connection) ugi.doAs(new PrivilegedExceptionAction&amp;lt;Object&amp;gt;() {
      public Object run() {
        Connection tcon = null;
        try {
          tcon = DriverManager.getConnection(connectionURL, user, passwd);
        } catch (SQLException e) {}
        return tcon;
      }
});&lt;/PRE&gt;&lt;P&gt;Refer to &lt;A href="https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-UsingJDBC"&gt;Hive Wiki&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 01:17:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95841#M9131</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-10-22T01:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95842#M9132</link>
      <description>&lt;P&gt;Couldn't add a longer reply for some reason so replied as an answer see below.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 01:17:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95842#M9132</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-10-22T01:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95843#M9133</link>
      <description>&lt;P&gt;It can use cache if you use loginUserFromSubject.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 21:00:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95843#M9133</guid>
      <dc:creator>hosako</dc:creator>
      <dc:date>2016-03-22T21:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting to Kerberos-enabled hive via JDBC directly from Java</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95844#M9134</link>
      <description>&lt;P&gt;I resolved the issue by using answer by &lt;A rel="user" href="https://community.cloudera.com/users/206/hosako.html" nodeid="206"&gt;@Hajime&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 21:47:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Connecting-to-Kerberos-enabled-hive-via-JDBC-directly-from/m-p/95844#M9134</guid>
      <dc:creator>madhura_verma</dc:creator>
      <dc:date>2016-11-28T21:47:33Z</dc:date>
    </item>
  </channel>
</rss>

