简体   繁体   中英

Connecting to Hive 2.3.0 using JDBC

First off, I want to apologize if this question turns out to be redundant. I did thoroughly research this site and the web in general before posting, to no avail. There is just so many different suggestions of which I have tried many and none of them worked out for me. I am trying to write a java program which would connect to Hive 2.3.0 in a remote cluster but keep getting an error.

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 CreateDB.main(CreateDB.java:12)
java.sql.SQLException: No suitable driver found for 
jdbc:hive://##########:####/default
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at CreateDB.main(CreateDB.java:20)
Exception in thread "main" java.lang.NullPointerException
at CreateDB.main(CreateDB.java:27)

I am using the code from this example on TutorialsPoint website (the "Create Database" example) I have included: hive-exec-0.8.1.jar hive-jdbc-3.1.0.3.1.0.0-78.jar hive-jdbc-3.1.0.3.1.0.0-78-sources.jar hadoop-common-2.4.0.jar in my build path, but it didn't solve the problem.

Thank you all in advance for any help that might be offered.

I will suggest to use a mavenized project rather a simple java project. Your pom must have the following jars.

Also refer the github example link

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-common</artifactId>
    <version>2.6.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>2.6.0-mr1</version>
</dependency>
<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-service</artifactId>
    <version>2.1.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-exec</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-metastore</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-service</artifactId>
    <version>1.1.0</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM