如何在 ubuntu 上使用 java jdbc 到 hive?

问题描述

Ubuntu 16.04.1 LTS
Hadoop 3.3.1
蜂巢 2.3.9

我有一个 java 文件:

public class HiveCreateDb {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {
        // Register driver and create driver instance
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.exit(1);
        }
        // get connection
        Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default","","");
        Statement stmt = con.createStatement();
        stmt.executeQuery("CREATE DATABASE userdb");
        System.out.println("Database userdb created successfully.");
        con.close();
    }
}

我把这个java文件放在ubuntu文件夹下,然后运行

javac HiveCreateDb.java 
HiveCreateDb.java:14: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
        Class.forName(driverName);
                     ^
1 error

我已经下载了hive-jdbc-3.1.2.jar,请问这个jar放在哪里?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)