I am facing this exception while connecting to beeline, hive2 version 1.2.1000.2.5.0.0, I have added hive-jdbc.jar file into classpath on my Windows 10 machine.
Exception:
java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at HiveJdbcClient.main(HiveJdbcClient.java:17)
HiveJdbcClient.java
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";
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);
}
//replace "hive" here with the name of the user the queries should run as
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10003/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
}
}
- I am not sure what other jars I need to add here?
- These jar files change based on the version of Hive?
- Does Cloudera and Hortonworks etc have different jar files, please visit this page, this is so confusing.
- Why it's so complicated to connect to Hive, I have my hive on Hortonworks, which is http://142.56.78.174:10003/default, and I have added hive-jdbc jar files to the classpath and I have my java class below. Isn't this enough?
- Please let me know what I am really missing.
Thanks for the answer, I have already tried this,
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
Thanks in advance!!