Wednesday, July 26, 2017

Hive JDBC Connection

package org.tek.Java.Javaprojects;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class hiveJdbcClient {

private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
try {
Class.forName(driverName);

} catch (Exception e) {
// TODO: handle exception
     e.printStackTrace();
     System.exit(1);
}

String hiveConn_Str = args[0].toString();
String ssh_User = args[1].toString();
String ssh_Pwd = args[2].toString();
// Connection con = DriverManager.getConnection("jdbc:hive2://10.188.193.152:10000/leela", "hadoop", "W3b!6xfMd");
Connection con = DriverManager.getConnection(hiveConn_Str, ssh_User, ssh_Pwd);
System.out.println("!!!!!!!!!!!!!!!!Connected!!!!!!!!!!!!");
Statement stmt = con.createStatement();

String sql = "show databases";
   System.out.println("Running: " + sql);
   ResultSet res = stmt.executeQuery(sql);
   while (res.next()) {
     System.out.println(res.getString(1));
   }
}

}

2 comments:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    https://www.emexotechnologies.com/online-courses/big-data-hadoop-training-in-electronic-city/

    ReplyDelete