java - ERROR jdbc.HiveConnection: Error opening session Hive -
i try run jbdc code hive2 error. have hive 1.2.0 version hadoop 1.2.1 version. in command line hive , beeline works fine without problem.but 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 name of user queries should run 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 error while run code.
15/06/19 12:08:53 info jdbc.hiveconnection: try open client transport 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' unset! struct:topensessionreq(client_protocol:null, configuration:{use:database=default}) @ org.apache.thrift.tapplicationexception.read(tapplicationexception.java:111) @ org.apache.thrift.tserviceclient.receivebase(tserviceclient.java:71) @ org.apache.hive.service.cli.thrift.tcliservice$client.recv_opensession(tcliservice.java:156) @ org.apache.hive.service.cli.thrift.tcliservice$client.opensession(tcliservice.java:143) @ org.apache.hive.jdbc.hiveconnection.opensession(hiveconnection.java:578) @ org.apache.hive.jdbc.hiveconnection.<init>(hiveconnection.java:192) @ org.apache.hive.jdbc.hivedriver.connect(hivedriver.java:105) @ java.sql.drivermanager.getconnection(drivermanager.java:571) @ java.sql.drivermanager.getconnection(drivermanager.java:215) @ hivejdbcclient.main(hivejdbcclient.java:24) exception in thread "main" java.sql.sqlexception: not establish connection jdbc:hive2://localhost:10000/default: required field 'client_protocol' unset! struct:topensessionreq(client_protocol:null, configuration:{use:database=default}) @ org.apache.hive.jdbc.hiveconnection.opensession(hiveconnection.java:589) @ org.apache.hive.jdbc.hiveconnection.<init>(hiveconnection.java:192) @ org.apache.hive.jdbc.hivedriver.connect(hivedriver.java:105) @ java.sql.drivermanager.getconnection(drivermanager.java:571) @ java.sql.drivermanager.getconnection(drivermanager.java:215) @ hivejdbcclient.main(hivejdbcclient.java:24) caused by: org.apache.thrift.tapplicationexception: required field 'client_protocol' unset! struct:topensessionreq(client_protocol:null, configuration:{use:database=default}) any solution ?
org.apache.thrift.tapplicationexception: required field 'client_protocol' unset! struct:topensessionreq(client_protocol:null, configuration:{use:database=default}) @ org.apache.thrift.tapplicationexception.read(tapplicationexception.java:111)
this error occurs if have version mismatch between hive , hive-jdbc. please check if both versions match.
please refer this more information.
Comments
Post a Comment