本文介绍了错误jdbc.HiveConnection:打开会话配置单元时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为Hive2运行JBDC代码获取错误。我有配置单元1.2.0版本的hadoop 1.2.1版本。
但在命令行配置单元和直线工作正常没有任何问题,但与jdbc获取错误。

  import java。 sql.SQLException; 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcClient {
private static String driverName =org.apache.hive.jdbc.HiveDriver;
$ b $ **
* @param args
* @throws SQLException
* /
public static void main(String [] args)throws SQLException {
//BasicConfigurator.configure();

尝试{
Class.forName(driverName);
} catch(ClassNotFoundException e){
// TODO自动生成的catch块
e.printStackTrace();
}
//将hive替换为用户的名字查询应该以
的形式运行Connection con = DriverManager.getConnection(jdbc:hive2:// localhost:10000 / default ,,);
Statement stmt = con.createStatement();
String tableName =cdr;
stmt.execute(drop drop if exists+ tableName);
//显示表格
字符串sql =显示表格+ tableName +';
System.out.println(Running:+ sql);
ResultSet res = stmt.executeQuery(sql);
if(res.next()){
System.out.println(res.getString(1));
}

}
}

运行代码时出现此错误。

  15/06/19 12:08:53 INFO jdbc。 HiveConnection:尝试使用JDBC打开客户端传输Uri:jdbc:hive2:// localhost:10000 / default 
15/06/19 12:08:53错误jdbc.HiveConnection:打开会话时出错
org .apache.thrift.TApplicationException:必填字段'client_protocol'未设置! Struct:TOpenSessionReq(client_protocol:null,配置:{use:database = default})
在org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
在org.apache.thrift。在org.apache.hive.service.cli.thrift.TCLIService $ Client.recv_OpenSession TServiceClient.receiveBase(TServiceClient.java:71)
(TCLIService.java:156)
。在org.apache.hive。 service.cli.thrift.TCLIService $ Client.OpenSession处org.apache org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:578)
(TCLIService.java:143)
。 hive.jdbc.HiveConnection。< init>(HiveConnection.java:192)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager .getConnection(DriverManager.java:571)
。在java.sql.DriverManager.getConnection(DriverManager.java:215)
。在HiveJdbcClient.main(HiveJdbcClient.java:24)
异常在螺纹mainjava.sql.SQLException:C不应建立与jdbc的连接:hive2:// localhost:10000 / default:必填字段'client_protocol'未设置! Struct:TOpenSessionReq(client_protocol:null,配置:{use:database = default})
位于org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:589)
位于org.apache。 hive.jdbc.HiveConnection。< init>(HiveConnection.java:192)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager .getConnection(DriverManager.java:571)
在java.sql.DriverManager.getConnection(DriverManager.java:215)
在HiveJdbcClient.main(HiveJdbcClient.java:24)
导致: org.apache.thrift.TApplicationException:必填字段'client_protocol'未设置! Struct:TOpenSessionReq(client_protocol:null,configuration:{use:database = default})

任何解决方案?

解决方案

如果您的配置单元和配置单元之间存在版本不匹配 -jdbc。请检查两个版本是否匹配。



请参阅,以获取更多信息。


i try to run JBDC code for Hive2 get error. i have hive 1.2.0 version hadoop 1.2.1 version.but in command line hive and beeline works fine without any problem.but with jdbc getting error.

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcClient {
  private static String driverName = "org.apache.hive.jdbc.HiveDriver";

  /**
   * @param args
   * @throws SQLException
   */
  public static void main(String[] args) throws SQLException {
//BasicConfigurator.configure();

  try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //replace "hive" here with the name of the user the queries should run as
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default","", "");
    Statement stmt = con.createStatement();
    String tableName = "cdr";
   stmt.execute("drop table if exists " + tableName);
// show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
    }

  }
}

i Get this Error While Run Code.

15/06/19 12:08:53 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
15/06/19 12:08:53 ERROR jdbc.HiveConnection: Error opening session
org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})
        at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
        at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:71)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:156)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:143)
        at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:578)
        at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:571)
        at java.sql.DriverManager.getConnection(DriverManager.java:215)
        at HiveJdbcClient.main(HiveJdbcClient.java:24)
Exception in thread "main" java.sql.SQLException: Could not establish connection to jdbc:hive2://localhost:10000/default: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})
        at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:589)
        at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:571)
        at java.sql.DriverManager.getConnection(DriverManager.java:215)
        at HiveJdbcClient.main(HiveJdbcClient.java:24)
Caused by: org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})

Any Solution ?

解决方案

This error mostly occurs if you have version mismatch between your hive and hive-jdbc. Please check if both the versions match.

Please refer this for more information.

这篇关于错误jdbc.HiveConnection:打开会话配置单元时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:25