0

Below is the exception I'm facing while trying to connect hive using jdbc connection.

Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "hive", "");

Error:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.thrift.protocol.TProtocol.getScheme()Ljava/lang/Class;
    at org.apache.hadoop.hive.service.ThriftHive$execute_args.write(ThriftHive.java:1076)
    at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:63)
    at org.apache.hadoop.hive.service.ThriftHive$Client.send_execute(ThriftHive.java:110)
    at org.apache.hadoop.hive.service.ThriftHive$Client.execute(ThriftHive.java:102)
    at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:187)
    at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
    at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
    at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
    at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:200)
    at HiveJdbcClient.main(HiveJdbcClient.java:24)

The class TProtocol.java in libthrift-0.9.0.jar doesn't have the method getScheme().

Can anyone please let me know which Jar file I need to use.

Thank you.

Olaf
  • 6,249
  • 1
  • 19
  • 37
Naveen
  • 425
  • 12
  • 28
  • what is the Hive version you are using? – Ankur Shanbhag Nov 12 '13 at 09:56
  • have you taken a look at https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-RunningtheJDBCSampleCode – Satya Nov 12 '13 at 09:56
  • Ankur.. I'm using hive version 0.10.0, CDH4.2.0 @Satya I looked into it, but I'm running in eclipse and added all necessary jar files mentioned there. – Naveen Nov 12 '13 at 10:26
  • what is the content of sqoop-env.sh – Satya Nov 12 '13 at 10:34
  • Sqoop is not installed yet. – Naveen Nov 12 '13 at 10:48
  • @Satya sry sqoop is installed. Below is the contents of sqoop-env.sh # Set CATALINA_BASE to: # /usr/lib/sqoop2/sqoop-server for YARN clusters # /usr/lib/sqoop2/sqoop-server-0.20 for MR1 clusters export CATALINA_BASE=${CATALINA_BASE:-"/usr/lib/sqoop2/sqoop-server"} – Naveen Nov 12 '13 at 10:59
  • to the best of my knowledge this happens when multiple thrift versions are available on available on sqoop path , would you mind rerunning the Sqoop job with parameter --verbose and sharing the output? – Satya Nov 12 '13 at 11:04
  • @Satya Just want to confirm if we both are in same page.. I got this error while running a simple Java program to connect hive. Can you please tell me which job you want me to run sqoop? Any general import statement with --verbose parameter? – Naveen Nov 12 '13 at 12:08
  • need to rush into something, will look into this later. – Satya Nov 12 '13 at 12:18
  • Can you check in your **/usr/lib/hive-0.9.0/lib** location whether **libthrift-0.9.0.jar** or **libthrift.jar** is present or not. If not try downloading it and place in that location. Hope this helps..:) – Mukesh S Nov 13 '13 at 06:31
  • Yes these jars are present in hive library, and referencing same Jar files in eclipse. – Naveen Nov 13 '13 at 08:50

1 Answers1

0

Try the below code....

package com.services.connections;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectHive
{
  public static void main(String[] args) throws SQLException,ClassNotFoundException
 {
    // TODO Auto-generated method stub
    String connectionURL = "jdbc:hive://localhost:9999/javatesting";
    String drivername = "org.apache.hadoop.hive.jdbc.HiveDriver";
    String username = "";
    String password = "";
    try {
        Class.forName(drivername);
            } 
        catch (ClassNotFoundException e)
          {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
          }
          try {
            Connection con = DriverManager.getConnection(connectionURL, username, password);
            if(con != null) 
            {
            System.out.println("Connected");
                }
            else
                {
            System.out.println("Not Connected");
            }
            Statement stmt = con.createStatement(); 
            // select * query
            String sql;
            ResultSet res;
            sql = "select * from javatesting.testdata";
            System.out.println("Running: " + sql);
                res = stmt.executeQuery(sql);
            while (res.next())
            {
                  System.out.println(String.valueOf(res.getString(1)) + "\t" + res.getString(2));
            }
              }
          catch(SQLException se) 
          {
            se.printStackTrace();
          }
  }

}
Sree Eedupuganti
  • 224
  • 4
  • 13