连接到EC2-Linux实例后,Hive无法连接

时间:2019-04-18 06:35:57

标签: java jdbc hive putty jsch

这是油灰图像:

enter image description here

我尝试连接到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)

0 个答案:

没有答案