I am using hadoop with kerberos environment and I am new to the kerberos. I wanted to access hive database using java, I gone through the hive official site but they given very generalize information.
Please somebody give me specific answer?
I think kerbrose implementation is pretty much vast concept and going through it for a small task could be time consuming.
Here is quick fix to your problem!
To access the hive and in secure environment do consider the following things:
- To access the hive you need to provide all jars specific to that hive version,as given a list on hive official site.
- Next Provide hive version specific driver name e.g. for hive server2 "org.apache.hive.jdbc.HiveDriver"
- Provide hive connection URL e.g. jdbc:hive2://node.addr:10000/default;principal=hive/node.addr@ABCREALM.LOCAL
We provide connection address and the security authentication in connection URL. For kerberos there will be the authentication string and that is the kerberos principle that we have set while kerberos implementation.
This string is same as the string we provide while connecting to hive server using beeline e.g. beeline -u "jdbc:hive2://node.addr:10000/default;principal=hive/node.addr@ABCREALM.LOCAL"
Here is a small code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
public class Connect {
private static ResultSet res;
public static void main(String[] args) throws Exception {
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("Process started at:"+new Date());
Connection con = DriverManager.getConnection("jdbc:hive2://node.addr:10000/default;principal=hive/node.addr@ABCREALM.LOCAL");
Statement stmt = con.createStatement();
stmt.execute("create table testTable (key string,col1 string)");
System.out.println("Table Created successfully");
con.close();
}
}