Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect hive remotely? #50

Open
IzayoiAster opened this issue Jul 5, 2022 · 1 comment
Open

How to connect hive remotely? #50

IzayoiAster opened this issue Jul 5, 2022 · 1 comment

Comments

@IzayoiAster
Copy link

I deployed it in Windows by docker desktop (wsl2)

"jdbc:hive2://localhost:10000" doesn't works:

package com.aster;

import java.sql.*;

public class HiveJdbcTest {
    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();
        }

        // 代码打包后,运行JAR包的环境需要在hosts文件中
        // 把localhost映射到集群的公网IP地址(或内网IP地址)。
        Connection con = DriverManager.getConnection(
                "jdbc:hive2://localhost:10000/deafult");

        Statement stmt = con.createStatement();

        String sql = "select * from pokes limit 10";
        ResultSet res = stmt.executeQuery(sql);

        while (res.next()) {
            System.out.println(res.getString(0) + "\t" + res.getString(1));
        }

    }
}
Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/deafult: java.net.SocketException: Connection reset
	at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:224)
	at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:270)
	at com.aster.HiveJdbcTest.main(HiveJdbcTest.java:18)
Caused by: org.apache.thrift.transport.TTransportException: java.net.SocketException: Connection reset
	at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:129)
	at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
	at org.apache.thrift.transport.TSaslTransport.receiveSaslMessage(TSaslTransport.java:178)
	at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:307)
	at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
	at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:311)
	at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:196)
	... 4 more
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:210)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:127)
	... 10 more

I also tried to connect to hive by IDEA, but test connection failed: Driver class 'org.apache.hive.service.rpc.thrift.TCLIService$Iface' not found.

@Santhoshkumard11
Copy link

@IzayoiAster Check this if it helps - Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants