INFO:Transport用于JDBC连接:null + Apache Hive

时间:2015-12-29 13:05:38

标签: java eclipse apache hadoop jdbc

我正在尝试通过JDBC连接Apache Hive和eclipse但遇到错误。以下是版本信息:     Apache Hadoop:2.7.1,Hive:1.2.1和Eclipse Kepler。

****Error :****
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Supplied authorities: localhost:10000
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Resolved authority: localhost:10000
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
Dec 29, 2015 6:04:00 PM org.apache.hive.jdbc.HiveConnection openTransport
INFO: Transport Used for JDBC connection: null
Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default: java.net.ConnectException: Connection refused
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:231)
    at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:176)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at test.JDBCtest.main(JDBCtest.java:25)
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused
    at org.apache.thrift.transport.TSocket.open(TSocket.java:187)
    at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:266)
    at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:204)
    ... 5 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.thrift.transport.TSocket.open(TSocket.java:182)
    ... 8 more

代码:

package test;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class JDBCtest {
  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://localhost:10000/default","","");

    System.out.println("Connected");

    Statement stmt = con.createStatement();
    String tableName = "testHiveDriverTable";
    stmt.executeQuery("drop table " + tableName);
    ResultSet res = 
    stmt.executeQuery("create table "+tableName+"(key int,value);

    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
    }

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


    String filepath = "/tmp/a.txt";
    sql="load data local inpath'"+filepath + "' into table " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);

    sql = "select * from " + 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));
    }

    sql = "select count(1) from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(res.getString(1));
    }
  }}

请耐心等待我们长期以来面临的上述错误。 提前致谢 Mehul

1 个答案:

答案 0 :(得分:1)

主要的例外是:

Caused by: java.net.ConnectException: Connection refused

您正在此行中打开没有用户名/密码的连接:

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

请验证数据库的用户名和密码。