问题描述
我对 Java 还很陌生.我正在尝试通过 java 连接到 Hive 服务器并使用来自 https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC
I'm pretty new to Java. I'm trying to connect to hive server through java and used sample code from https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC
import java.sql.SQLException;
public class HiveJdbcClient {
//private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
}
}
我将所有 jars 放在所需的位置并更新了 pom 文件,但得到
I placed all the jars in the required location and updated the pom file, but getting
java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
at java.net.URLClassLoader.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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at HiveJdbcClient.main(HiveJdbcClient.java:7)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
我找了很长时间的解决方案,但无法解决.请让我知道如何解决这个问题.
I searched for a solution for quite some time, but couldn't solve it. Please let me know how to fix this.
推荐答案
这是由于 hivesever2 版本不匹配造成的.如果 Hive 版本超过 0.13 那么你可能不得不使用这个.
This is due to mismatch in hivesever2 version.If Hive version is more than 0.13 then You may have to use this.
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
还要确保在类路径中添加这个 jar..
Also make sure you add this jar in you class path..
这篇关于ClassNotFoundException: org.apache.hive.jdbc.HiveDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!