Hi
This article Explains to you how to write a JDBC program to connect Hive with Kerbose Authentication.
Here writing Java program is very simple and easy you can see the java code Below.
But I have struggled to get all the support jar files. here I have attached the lib file folder you can use directly.
Java Code:
=====================
import java.sql.*;
import java.sql.Statement;
import org.apache.hadoop.security.UserGroupInformation;
public class test {
public static void main (String args[]) {
try {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "kerberos");
// conf.set(name, value);
UserGroupInformation.setConfiguration(conf);
System.out.println("started");
UserGroupInformation.loginUserFromKeytab("cloudera@quickstart.cloudera", "keytabpath");
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("getting connection");
Connection con = DriverManager.getConnection("jdbc:hive2://quickstart.cloudera/default;principal=hive/_HOST@quickstart.cloudera;");
System.out.println("got connection");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Download the source code and jar
This article Explains to you how to write a JDBC program to connect Hive with Kerbose Authentication.
Here writing Java program is very simple and easy you can see the java code Below.
But I have struggled to get all the support jar files. here I have attached the lib file folder you can use directly.
Java Code:
=====================
import java.sql.*;
import java.sql.Statement;
import org.apache.hadoop.security.UserGroupInformation;
public class test {
public static void main (String args[]) {
try {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "kerberos");
// conf.set(name, value);
UserGroupInformation.setConfiguration(conf);
System.out.println("started");
UserGroupInformation.loginUserFromKeytab("cloudera@quickstart.cloudera", "keytabpath");
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("getting connection");
Connection con = DriverManager.getConnection("jdbc:hive2://quickstart.cloudera/default;principal=hive/_HOST@quickstart.cloudera;");
System.out.println("got connection");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Download the source code and jar
It is very helpful..
ReplyDelete