0

下面是我在尝试使用 jdbc 连接连接 hive 时遇到的异常。

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

错误:

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)

该类TProtocol.java in libthrift-0.9.0.jar没有方法getScheme()

谁能告诉我我需要使用哪个 Jar 文件。

谢谢你。

4

1 回答 1

0

试试下面的代码......

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

}
于 2015-02-24T07:08:23.383 回答