gpt4 book ai didi

hadoop - 远程访问 hive

转载 作者:可可西里 更新时间:2023-11-01 14:33:19 28 4
gpt4 key购买 nike

我正在研究 Hive。我想通过 Hive JDBC 访问 Hive 表。我正在使用的代码如下:

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){
e.printStackTrace();
System.exit(1);
}

Connection connection = DriverManager.getConnection("jdbc:hive2://aaaa:10000", "" , "");
Statement statement = connection.createStatement();
String tableName = "tmp_ext_h;

/**
* SELECT* QUERY
* */
String sql = "select * from " + tableName;
System.out.println("Running: " + sql);
ResultSet result = statement.executeQuery(sql);
while (result.next()){
System.out.println(String.valueOf(result.getInt(1)) + "\t" + result.getString(2));

}

/**
* REGULAR HIVE QUERY
* */
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
result = statement.executeQuery(sql);
while (result.next()){
System.out.println(result.getString(1));
}
}
}

我的图书馆是:

hive-jdbc.jar"
hive-exec.jar"

hive-metastore.jar"

hive-service.jar"

libthrift-0.9.0.jar"

mysql-connector-java.jar"

运行时出现错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/facebook/fb303/FacebookService$Iface
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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 org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at hadoop_HiveConnector.HiveJdbcClient.main(HiveJdbcClient.java:28)
enter code here

有人知道问题出在哪里吗?我是 Hive 的新手

谢谢。

最佳答案

根据这个http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/HiveJDBCDriver.html

Hive 0.13 需要以下 jar:

hive_metastore.jar
hive_service.jar
HiveJDBC3.jar
libfb303-0.9.0.jar
libthrift-0.9.0.jar
log4j-1.2.14.jar
ql.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
TCLIServiceClient.jar

但是它会根据环境和版本而变化。在您的情况下,至少您缺少 libfb303-*.jar

关于hadoop - 远程访问 hive ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32455499/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com