1

I am trying to connect to hive server using java. I am runnig the code in Eclipse Oxygen and has Java 8 installed.

private static String driverName = "org.apache.hive.jdbc.HiveDriver";    
public static void main(String[] args) throws SQLException 
{
    try 
    {
        Class.forName(driverName);
    } 
    catch (ClassNotFoundException e) 
    {
        e.printStackTrace();
        System.exit(1);
    }
    Connection con = DriverManager.getConnection("jdbc:hive2://<IP>:port/database", "username", "password");        
    Statement stmt = con.createStatement();      
    String sql = "show tables";
    stmt.executeQuery(sql);
}

These are the external libraries I am using.

commons-logging-1.2
curator-client-2.0.0-incubating
hadoop-common-3.1.0
hive-exec-3.0.0
hive-jdbc-3.0.0
hive-metastore-3.0.0
hive-service-3.0.0
hive-service-rpc-2.1.0
httpclient-4.5.6
httpcore-4.4.10
libfb303-0.9.3
libthrift-0.9.3
log4j-1.2.17
slf4j-api-1.8.0-beta2

When I run the code I am getting the following error.

java.lang.NoSuchMethodError: org.apache.hive.service.auth.HiveAuthFactory.getSocketTransport(Ljava/lang/String;II)Lorg/apache/thrift/transport/TTransport

I can't figure out what is causing the error. I tried different versions of jars. Am I missing any library? Please help me.

HSP
  • 67
  • 2
  • 11
  • Does this help? https://stackoverflow.com/questions/34540948/unable-to-connect-to-hive2-via-java – Andrea Jul 13 '18 at 10:17
  • Hi, as your link and their related links suggested I updated my versions to the latest and added new jars. I have updated them above. The error is gone. But now I am getting "NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V9". Looking into it now. Thanks for helping. – HSP Jul 13 '18 at 11:11

0 Answers0