无法使用Java代码连接到Hive

时间:2019-06-01 09:57:53

标签: hadoop jdbc hive

我可以使用Beeline连接到蜂巢。但是无法通过JDBC连接。我正在获取版本信息“相关错误”。

错误:org.apache.hadoop.hive.metastore.RetryingHMSHandler MetaException错误(消息:在metastore中找不到版本信息。)

private static String driverName = "org.apache.hive.jdbc.HiveDriver";

public static void main(String[] args) throws SQLException, ClassNotFoundException {
    // Register driver and create driver instance

    Class.forName(driverName);
    // get connection

    Connection con = DriverManager.getConnection("jdbc:hive2://", "", "");
    System.out.println("Connection: " + con.getCatalog());
    Statement stmt = con.createStatement();

    stmt.executeQuery("CREATE DATABASE userdb");
    System.out.println("Database userdb created successfully.");

    con.close();
}

下面是pom的详细信息。

<dependency>
     <groupId>org.apache.hive</groupId>
     <artifactId>hive-jdbc</artifactId>
     <version>3.1.1</version>
</dependency>
<dependency>
     <groupId>org.apache.hive</groupId>
     <artifactId>hive-exec</artifactId>
     <version>3.1.1</version>
</dependency>
<dependency>
     <groupId>org.apache.hadoop</groupId>
     <artifactId>hadoop-common</artifactId>
     <version>3.2.0</version>
</dependency>

请帮助

0 个答案:

没有答案