Hive не подключается после подключения к экземпляру ec2-linux - PullRequest
0 голосов
/ 18 апреля 2019

Это изображение замазки:

enter image description here

Я попытался подключиться к своей Putty и смог подключиться, затем попытался подключиться к Hive с JDBC, но все еще столкнулся с той же проблемой подключения. Вот мой код.

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)
...