Connect to Hive database

One Star

Connect to Hive database

I am not able to connect to Hive database can anyone help me out
One Star

Re: Connect to Hive database

When i am using general JDBC during connection with the Hive database i am passing everything correctly even then its not able to connect to the database
One Star

Re: Connect to Hive database

DB Type: General JDBC
JDBC Url: jdbc:hive://<iP Address>172.17.197.95:<port No.>8099/<databasename>default
Driver Jar: /usr/local/Talend/lib/java/hive-jdbc-0.5.0.jar
Class Name : org.apache.hadoop.hive.jdbc.HiveDriver

After giving all these details also i am not able to connect to the database
please help me out in establishing the database connection
Community Manager

Re: Connect to Hive database

Hi honeybakliwal
I don't have a Hive database installation here, so I can't test it now and I will do it later. Can you create a routine to test this code (JDBC Client Sample Code)and see if it connect successfully to your Hive.
http://wiki.apache.org/hadoop/Hive/HiveClient
Let me know your test result!
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Connect to Hive database

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClient {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
// describe table
sql = "describe " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
// load data into table
// NOTE: filepath has to be local to the hive server
// NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
String filepath = "/tmp/a.txt";
sql = "load data local inpath '" + filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
// select * query
sql = "select * from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
// regular hive query
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
}
}
One Star

Re: Connect to Hive database

i have alread used this also but no success
Community Manager

Re: Connect to Hive database

Hi
Create a job contains tHiveConnecton and run the job. Have you changed the port from 10000 to 8099?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Connect to Hive database

ya i have done dat also
One Star

Re: Connect to Hive database

but neither i am able to see the tables present in hive neither able to fetch the data
i am surprised when the driver is already present there even then y it is nt able to connect to it
Community Manager

Re: Connect to Hive database

Hi
So you have to check the db installation is completely or not, have you turned off the firewall? Can you connect to Hive database with other client tool?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business