我是hadoop新手。我使用的是ubuntu,安装了hadoop、hive和pig。我正在尝试用java创建一个接口来获取配置单元查询并在后台执行它。
我正在使用ide eclipse-mars
源代码
package com.soniya.demo2;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class TestJdb
{
private static String driver = "org.hadoop.apache.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Connection connect = DriverManager.getConnection("jdbc:hive2://:16074/default","","");
Statement state = connect.createStatement();
String tableName = "test";
state.executeQuery("drop table " + tableName);
ResultSet res = state.executeQuery("create table " + tableName + " (key int, value string)");
// Query to show tables
String show = "show tables";
System.out.println("Running show");
res = state.executeQuery(show);
if (res.next()) {
System.out.println(res.getString(1));
}
// Query to describe table
String describe = "describe " + tableName;
System.out.println("Running describe");
res = state.executeQuery(describe);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
}
}
我得到以下错误
java.lang.ClassNotFoundException: org.hadoop.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 com.soniya.demo2.TestJdb.main(TestJdb.java:21)
帮我解决这个问题。我已经包括了像hivejdbc、hadoop common这样的jar文件,但它不起作用,还尝试了hivelib jar文件,但仍然出现同样的错误。提前谢谢
1条答案
按热度按时间5vf7fwbs1#
尝试将drivername“org.apache.hive.jdbc.hivedriver”替换为“org.apache.hadoop.hive.jdbc.hivedriver”;