简体   繁体   中英

Exception while connecting to hive through jdbc

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.

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();
          }
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM