Home Forums Hive / HCatalog Connection refused to HiveServer2 via JDBC

This topic contains 8 replies, has 3 voices, and was last updated by  Siva Prakash 6 months, 1 week ago.

  • Creator
    Topic
  • #43601

    Vivek Ganesan
    Participant

    Hi,

    I am trying to connect to HiveServer2 via JDBC but I am getting “Connection refused” error.

    org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused
    at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
    at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:248)
    at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:156)
    at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:96)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at TestClass.main(TestClass.java:21)
    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:180)
    … 8 more
    Exception in thread “main” java.sql.SQLException: Could not establish connection to jdbc:hive2://localhost:10000/default: java.net.ConnectException: Connection refused
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:159)
    at org.apache.hive.jdbc.Hive
    Connection.(HiveConnection.java:96)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at TestClass.main(TestClass.java:21)

    Following is the java code which I am using. Am I doing something wrong?

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    public class TestClass {

    public static void main(String[] args) throws Exception{

    try {
    String driverName = “org.apache.hive.jdbc.HiveDriver”;
    Class.forName(driverName);
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.exit(1);
    }
    Connection con = DriverManager.getConnection(“jdbc:hive2://localhost:10000/default”, “”, “”);
    Statement stmt = con.createStatement();
    String tableName = “testHiveDriverTable”;
    stmt.executeQuery(“drop table ” + tableName);
    ResultSet res = stmt.executeQuery(“create table ” + tableName + ” (key int, value string)”);
    // show tables
    String sql = “show tables ‘” + tableName + “‘”;
    System.out.println(“Running: ” + sql);
    res = stmt.executeQuery(sql);
    }
    }

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

  • Author
    Replies
  • #50060

    Siva Prakash
    Participant

    Thanks @Vivek , i am using vsphere client. vm is running on vsphere, i dont have the options to change to bridge mode. i dont know where to add those changes . how to access from outside/inside box. same program works smoothly in cloudera setup. but i am checking in hortonworks setup not able to run a simple hive jdbc program in vsphere. please guide me how to change the required properties. i am new to this hadoop/hortonworks environment..

    Collapse
    #50035
    Collapse
    #50034

    Siva Prakash
    Participant

    any suggestion for vm ware settings. i am not able to connect hive jdbc .for the above program.

    Collapse
    #43725

    Vivek Ganesan
    Participant

    Hi Carter,

    Thanks! I was using the jars from wrong hive version.

    Summarizing, these are the steps I did to resolve this issue:

    1. Added a port-forwarding rule to 10000 port of the guest. (This is not present in the default settings of Hortonworks sandbox vm)
    2. Downloaded Hive jars (of version, which is specified in the Hortonworks sandbox home page)
    3. Added the above jars in classpath and ran the code specified in this forum question.

    Collapse
    #43717

    Vivek Ganesan
    Participant

    Hi Carter,

    Thanks! Port forwarding did the trick. :)

    But, now i am one stage ahead but with a different problem

    I get this error now :

    Required field ‘serverProtocolVersion’ is unset! Struct:TOpenSessionResp(status:TStatus(statusCode:SUCCESS_STATUS), serverProtocolVersion:null, sessionHandle:TSessionHandle(sessionId:THandleIdentifier(guid:E5 63 9F BC 98 9F 4E EE 92 46 21 EC A0 51 11 C4, secret:F3 ED E6 FA F3 EC 4C BB 99 F1 74 77 5F 01 98 23)), configuration:{})

    Any idea how to handle this? Googling did not help :(

    Regards,
    Vivek Ganesan

    Collapse
    #43702

    Carter Shanklin
    Participant

    Hi Vivek,

    Yes, JDBC does work.

    Looks like you’re using the VirtualBox Sandbox since your IP is 127.0.0.1. (If you are using VMware there is something wrong with the networking).

    Anyway, VirtualBox relies on port forwards to be able to communicate to the ports. Check to ensure there is a port forward for port 10000. You won’t be able to get it to work until you are able to connect using telnet.

    Collapse
    #43677

    Vivek Ganesan
    Participant

    Hi Carter,

    I tried connecting to port 10000 using telnet using “localhost” and “127.0.0.1″(the ip address which my Hortonworks sandbox is showing just after starting up.

    I am not able to connect via both.

    Has anyone else faced this situation? Has anyone connected to HiveServer (or HiveServer2) of Hortonworks Sandbox using JDBC?

    Collapse
    #43630

    Carter Shanklin
    Participant

    Hi Vivek,

    Verify something is listening on localhost:10000 using a tool like telnet or curl. Otherwise your code looks good from here. You might try using an externally accessible hostname or IP if that doesn’t work.

    Collapse
Viewing 8 replies - 1 through 8 (of 8 total)