hadoop - Unable to connect to Hive through Java Application -


i trying connect hive2 through java application getting following error -

exception in thread "main" java.sql.sqlexception: [simba][hivejdbcdriver](500310) invalid operation: peer indicated failure: unsupported mechanism type plain;          @ com.cloudera.hive.hivecommon.api.hiveserver2clientfactory.createtransport(hiveserver2clientfactory.java:224)         @ com.cloudera.hive.hive.api.extendedhs2factory.createclient(extendedhs2factory.java:38)         @ com.cloudera.hive.hivecommon.core.hivejdbcconnection.connect(hivejdbcconnection.java:597)         @ com.cloudera.hive.jdbc.common.baseconnectionfactory.doconnect(baseconnectionfactory.java:219)         @ com.cloudera.hive.jdbc.common.abstractdriver.connect(abstractdriver.java:216)         @ java.sql.drivermanager.getconnection(drivermanager.java:664)         @ java.sql.drivermanager.getconnection(drivermanager.java:247)     caused by: com.cloudera.hive.support.exceptions.generalexception: [simba][hivejdbcdriver](500310) invalid operation: peer indicated failure: unsupported mechanism type plain;         ... 7 more     caused by: org.apache.thrift.transport.ttransportexception: peer indicated failure: unsupported mechanism type plain         @ org.apache.thrift.transport.tsasltransport.receivesaslmessage(tsasltransport.java:190)         @ org.apache.thrift.transport.tsasltransport.open(tsasltransport.java:288)         @ org.apache.thrift.transport.tsaslclienttransport.open(tsaslclienttransport.java:37)         @ com.cloudera.hive.hivecommon.api.hiveserver2clientfactory.createtransport(hiveserver2clientfactory.java:210)         @ com.cloudera.hive.hive.api.extendedhs2factory.createclient(extendedhs2factory.java:38)         @ com.cloudera.hive.hivecommon.core.hivejdbcconnection.connect(hivejdbcconnection.java:597)         @ com.cloudera.hive.jdbc.common.baseconnectionfactory.doconnect(baseconnectionfactory.java:219)         @ com.cloudera.hive.jdbc.common.abstractdriver.connect(abstractdriver.java:216)         @ java.sql.drivermanager.getconnection(drivermanager.java:664)         @ java.sql.drivermanager.getconnection(drivermanager.java:247)         @ hive2.hive.main(hive.java:30) 

i used follwoing documentation same cloudera: https://www.cloudera.com/documentation/other/connectors/hive-jdbc/2-5-4.html appreciated. trying following connection string :- connection con = drivermanager.getconnection("jdbc:hive2://server.com:12345/default;principal=hive/_org.com","user_id","pwd");

the complete code :

package hive2; import java.sql.sqlexception; import java.sql.connection; import java.sql.resultset; import java.sql.statement;   import java.sql.drivermanager;  public class hive {   private static string drivername = "com.cloudera.hive.jdbc4.hs2driver";    public static void main(string[] args) throws sqlexception {     try {       class.forname(drivername);     } catch (classnotfoundexception e) {       // todo auto-generated catch block       e.printstacktrace();       system.exit(1);     }         connection con = drivermanager.getconnection("jdbc:hive2://server.com:12345/default;principal=hive/_org.com","user_id","pwd");     statement stmt = con.createstatement();     string tablename = "testhivedrivertable";     stmt.executequery("drop table " + tablename);     resultset res = stmt.executequery("create table " + tablename + " (key int, value string)");     // show tables     string sql = "show tables '" + tablename + "'";     system.out.println("running: " + sql);     res = stmt.executequery(sql);     if (res.next()) {       system.out.println(res.getstring(1));     }     // describe table     sql = "describe " + tablename;     system.out.println("running: " + sql);     res = stmt.executequery(sql);     while (res.next()) {       system.out.println(res.getstring(1) + "\t" + res.getstring(2));     }      // load data table     // note: filepath has local hive server     // note: /tmp/a.txt ctrl-a separated file 2 fields per line     string filepath = "/tmp/a.txt";     sql = "load data local inpath '" + filepath + "' table " + tablename;     system.out.println("running: " + sql);     res = stmt.executequery(sql);      // select * query     sql = "select * " + tablename;     system.out.println("running: " + sql);     res = stmt.executequery(sql);     while (res.next()) {       system.out.println(string.valueof(res.getint(1)) + "\t" + res.getstring(2));     }      // regular hive query     sql = "select count(1) " + tablename;     system.out.println("running: " + sql);     res = stmt.executequery(sql);     while (res.next()) {       system.out.println(res.getstring(1));     }   } } 

driver class in code odbc driver, cannot used jdbc connection hiveserver2. refer below apache hive url jdbc connection.

below sample code snippet hiveserver2 jdbc connection.

https://cwiki.apache.org/confluence/display/hive/hiveclient#hiveclient-jdbc

dependent jar given in documentation, can find these dependent jars in hive lib path. (/opt/cloudera/cdh/hive/lib/*)


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -