无法通过JDBC java程序连接hive2

时间:2018-05-30 13:10:26

标签: java hadoop jdbc hive hiveql

enter image description here

因为我导入了所有必需的JAR文件,如上图所示。 但是在尝试通过java程序连接hive2时,它仍然会出错。

错误让我在这一行。

Connection connect = DriverManager.getConnection(“jdbc:hive2:// localhost:10000 / default”,“”,“”);

错误:

18/05/30 17:12:15 INFO jdbc.Utils: Supplied authorities: localhost:10000
18/05/30 17:12:15 INFO jdbc.Utils: Resolved authority: localhost:10000
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.hive.common.auth.HiveAuthUtils.getSocketTransport(Ljava/lang/String;II)Lorg/apache/thrift/transport/TTransport;
    at org.apache.hive.jdbc.HiveConnection.createUnderlyingTransport(HiveConnection.java:519)
    at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:539)
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:309)
    at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:196)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at Hive_java.main(Hive_java.java:15)

JAVA代码:

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class Hive_java{
  private static String driver = "org.apache.hive.jdbc.HiveDriver";  //driver used for hiveserver2
  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://localhost:10000/default", "", "");   //connecting to default database
    Statement state = connect.createStatement();
    System.out.println("!!!!!!!!!!Running 1st query!!!!!!!!!!");
    System.out.println("Listing tables in hive");
    ResultSet show_tables = state.executeQuery("show tables");
    while (show_tables.next()) {
        System.out.println(show_tables.getString(1));
    }
    System.out.println("!!!!!!!!!!Running 2nd query!!!!!!!!!!");
    System.out.println("Describing slave3_tbl table");
    ResultSet describe_table = state.executeQuery("describe slave3_tbl");
    while (describe_table.next()) {
        System.out.println(describe_table.getString(1) + "\t" + describe_table.getString(2));
      }
  }
}

0 个答案:

没有答案