简体   繁体   English

Hive JDBC Connection NoClassDefFoundError

[英]Hive JDBC Connection NoClassDefFoundError

I am using Hive 2.1.1 and trying to create a connection. 我正在使用Hive 2.1.1并尝试创建连接。 Following is the code I am trying: 以下是我正在尝试的代码:

private static String driverName = "org.apache.hive.jdbc.HiveDriver";

public static void main(String[] args) throws SQLException, ClassNotFoundException {
    // Register driver and create driver instance

    Class.forName(driverName);
    // get connection

    Connection con = DriverManager.getConnection("jdbc:hive2://", "", "");
    Statement stmt = con.createStatement();

    stmt.executeQuery("CREATE DATABASE userdb");
    System.out.println("Database userdb created successfully.");

    con.close();
}

These are my classpaths declared in bashrc: 这些是我在bashrc中声明的类路径:

CLASSPATH=$CLASSPATH:/usr/lib/hive/lib/hive-jdbc-2.1.1.jar CLASSPATH=$CLASSPATH:/usr/local/hadoop/lib/*:. CLASSPATH = $ CLASSPATH:/usr/lib/hive/lib/hive-jdbc-2.1.1.jar CLASSPATH = $ CLASSPATH:/ usr / local / hadoop / lib / *:。 CLASSPATH=$CLASSPATH:/usr/local/apache-hive-2.1.1-bin/lib CLASSPATH = $ CLASSPATH:/usr/local/apache-hive-2.1.1-bin/lib

I am getting the error below. 我收到以下错误。

ERROR StatusLogger No log4j2 configuration file found. 错误StatusLogger找不到log4j2配置文件。 Using default configuration: logging only errors to the console. 使用默认配置:仅将错误记录到控制台。 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/ql/metadata/HiveException at org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService.(EmbeddedThriftBinaryCLIService.java:33) at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:163) at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.raad.ams.bean.HiveJdbc.main(HiveJdbc.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.ql.metadata.HiveException at java.net.URLClassL 线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / hadoop / hive / ql / metadata / HiveException org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService。(EmbeddedThriftBinaryCLIService.java:33)at org。 apache.hive.jdbc.HiveConnection。(HiveConnection.java:163)atg.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)at java.sql.DriverManager.getConnection(DriverManager.java:664)at at java.ql.DriverManager.getConnection(DriverManager.java:247)位于sun.reflect的sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)的com.raad.ams.bean.HiveJdbc.main(HiveJdbc.java:17)中。 Native.MethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at com.intellij.rt.execution .application.AppMain.main(AppMain.java:147)由java.net.URLClassL引起的:java.lang.ClassNotFoundException:org.apache.hadoop.hive.ql.metadata.HiveException oader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) oader.findClass(URLClassLoader.java:381)位于java.lang.ClassLoader.loadClass(ClassLoader.java:424)的sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)at java.lang.ClassLoader.loadClass (ClassLoader.java:357)

Any help would be appreciated. 任何帮助,将不胜感激。

Here is what i would suggest : Create a Maven/ Gradle project and add Hive-jdbc in pom. 以下是我的建议:创建一个Maven / Gradle项目并在pom中添加Hive-jdbc。 It will download all dependencies. 它将下载所有依赖项。

Otherwise check this : Dependencies 否则请检查: 依赖关系

You need to include all jars which are under dependencies tag. 您需要包含所有依赖项标签下的jar。

I encountered a similar issue where we were getting noclassdeffound error working on Robot automation framework and Hive . 我遇到了类似的问题,我们在Robot automation frameworkHive上遇到了noclassdeffound错误。 It looks to be jar compatibility issue. 它看起来是jar兼容性问题。 We resolved it by adding the latest hive jdbc maven dependency to the pom file and it worked. 我们通过将最新的hive jdbc maven依赖项添加到pom文件来解决它,并且它工作正常。 You should check for all the required Hive related jars and update them accordingly. 您应该检查所有必需的Hive相关jar并相应地更新它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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