1. 程式人生 > >hive jdbc 連線時拋異常

hive jdbc 連線時拋異常

Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://192.168.137.200:10000/default: java.net.ConnectException: Connection refused: connect
     at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:215)
     at org.apache.hive.jdbc.HiveConnection
.<init>(HiveConnection.java:163) 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 HelloHive.main(HelloHive.java:17) Caused by: org.apache
.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect 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:190) ... 5 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) 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.PlainSocketImpl.connect(PlainSocketImpl.java:172) 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

在使用hive的時候啟動hiveserver2正常,但是寫java程式碼使用jdbc連結時一直報錯,真的是找了兩天才解決,jar包驅動全部都沒錯,就是執行java程式碼的時候報錯
1. 我先檢查hive server2是否啟動:
netstat -anp |grep 10000
完全正常
2. 檢查conf/hive-site.xml 下的配置也正常

 <configuration>
      <property> 
       <name>hive.server2.thrift.port</name> 
      <value>10000</value> 
    </property>
    <property>
       <name>hive.server2.thrift.bind.host</name>
       <value>192.168.206.128</value>
     </property>
    </configuration>

3 ip之間也能平通;
這是我就在想,報的是驅動錯誤,hiverserver2能啟動,在虛擬機器上使用./beeline -u jdbc:hive2://192.168.137.200:10000/default都沒有問題,那最後一個可能只有是虛擬機器的問題了,這是我開啟vi /etc/sysconfig/networt-scripts/ifcfg-eth0,發現果然,少了一行:device=eth0,加上這一行,最終問題解決了。。。。