Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Connect to Hive database

I am not able to connect to Hive database can anyone help me out
Labels (2)
9 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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));
}
}
}
Anonymous
Not applicable
Author

i have alread used this also but no success
Anonymous
Not applicable
Author

Hi
Create a job contains tHiveConnecton and run the job. Have you changed the port from 10000 to 8099?
Best regards
Shong
Anonymous
Not applicable
Author

ya i have done dat also
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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