Member since
05-27-2016
1
Post
0
Kudos Received
0
Solutions
12-18-2018
03:46 PM
If you already have a TGT available in cache, then below code worked for me import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
class HiveBeelineTest {
public static void main(String args[]) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.hive.jdbc.HiveDriver");
Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
Connection con = DriverManager.getConnection(
"jdbc:hive2://mynode.foobar.com:10000/default;principal=hive/mynode.foobar.com@FOOBAR.COM")
Statement sqlstatement = con.createStatement();
ResultSet result = sqlstatement.executeQuery("select test_column from test_table");
while (result.next()) {
System.out.println(result.getString(1));
}
}
}
... View more