如何在ubuntu上使用java实现jdbc的hive



Ubuntu 16.04.1 LTS
hadoop 3.3.1
Hive 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放在哪里?

javac-classpath jars/hive-jdbc-2.33.9.jar source/HiveCreateDb.java

相关内容

  • 没有找到相关文章

最新更新