hive在连接到ec2 linux示例后无法连接

i86rm4rw  于 2021-06-24  发布在  Hive
关注(0)|答案(0)|浏览(294)

这是油灰图像:

我试着连接到我的putty并且能够连接,然后试着用jdbc连接到hive,但是仍然面临同样的连接问题。这是我的密码。

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

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class SSHFile2 {

    static int lport;
    static String rhost;
    static int rport;
    public static void go(){
        String user = "ec2-user";
        //String password = "";
        String host = "18.188.88.49";
        int port=22;
        try
            {
            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, port);
            lport = 4321;
            rhost = "localhost";
            rport = 10000;
            //session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");
            System.out.println("Establishing Connection...");
            session.connect();
            int assinged_port=session.setPortForwardingL(lport, rhost, rport);
            System.out.println("localhost:"+assinged_port+" -> "+rhost+":"+rport);
            }
        catch(Exception e){System.err.print(e);}
    }
    public static void main(String[] args) {
        try{
            go();
        } catch(Exception ex){
            ex.printStackTrace();
        }
          System.out.println("An example for updating a Row from Hive Database!");
          Connection con = null;
          String driver = "org.apache.hive.jdbc.HiveDriver";
          String url = "jdbc:hive2://" + rhost +":" + lport + "/";
          String db = "sahoo";
          String dbUser = "hive";
          String dbPasswd = "";
          try{
          Class.forName(driver);
          con = DriverManager.getConnection(url+db, dbUser, dbPasswd);
          try{
          Statement st = con.createStatement();
          System.out.println("Connected to Hive");
          /*String sql = "UPDATE MyTableName " +
                  "SET email = 'ripon.wasim@smile.com' WHERE email='peace@happy.com'";

          int update = st.executeUpdate(sql);
          if(update >= 1){
          System.out.println("Row is updated.");
          }
          else{
          System.out.println("Row is not updated.");
          }

* /          }

          catch (SQLException s){
          System.out.println("SQL statement is not executed!");
          }
          }
          catch (Exception e){
          e.printStackTrace();
          }
          }

}

在这之后我收到了这个信息。虽然我不知道lport,但它到底是用来做Hive的。
这是错误报告:

com.jcraft.jsch.JSchException: Auth failApr 18, 2019 4:56:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Supplied authorities: localhost:4321
Apr 18, 2019 4:56:00 PM org.apache.hive.jdbc.Utils parseURL
INFO: Resolved authority: localhost:4321
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

INFO: Transport Used for JDBC connection: null
java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:4321/sahoo: java.net.ConnectException: Connection refused: connect
    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(Unknown Source)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题