Tuesday 17 April 2018

JDBC Java Program to connect HIVE Database with Kerbose authentication

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

1 comment:

java.io.IOException: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact Return code is: 400, ReasonPhrase: Repository does not allow updating assets: releases.

 HI, by Default in Nexus release branch will not allow redeploy of the Same version of Talend job. if we need to redeploy same job again int...