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

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

这是油灰图像:

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

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import com.jcraft.jsch.JSch;
  6. import com.jcraft.jsch.Session;
  7. public class SSHFile2 {
  8. static int lport;
  9. static String rhost;
  10. static int rport;
  11. public static void go(){
  12. String user = "ec2-user";
  13. //String password = "";
  14. String host = "18.188.88.49";
  15. int port=22;
  16. try
  17. {
  18. JSch jsch = new JSch();
  19. Session session = jsch.getSession(user, host, port);
  20. lport = 4321;
  21. rhost = "localhost";
  22. rport = 10000;
  23. //session.setPassword(password);
  24. session.setConfig("StrictHostKeyChecking", "no");
  25. System.out.println("Establishing Connection...");
  26. session.connect();
  27. int assinged_port=session.setPortForwardingL(lport, rhost, rport);
  28. System.out.println("localhost:"+assinged_port+" -> "+rhost+":"+rport);
  29. }
  30. catch(Exception e){System.err.print(e);}
  31. }
  32. public static void main(String[] args) {
  33. try{
  34. go();
  35. } catch(Exception ex){
  36. ex.printStackTrace();
  37. }
  38. System.out.println("An example for updating a Row from Hive Database!");
  39. Connection con = null;
  40. String driver = "org.apache.hive.jdbc.HiveDriver";
  41. String url = "jdbc:hive2://" + rhost +":" + lport + "/";
  42. String db = "sahoo";
  43. String dbUser = "hive";
  44. String dbPasswd = "";
  45. try{
  46. Class.forName(driver);
  47. con = DriverManager.getConnection(url+db, dbUser, dbPasswd);
  48. try{
  49. Statement st = con.createStatement();
  50. System.out.println("Connected to Hive");
  51. /*String sql = "UPDATE MyTableName " +
  52. "SET email = 'ripon.wasim@smile.com' WHERE email='peace@happy.com'";
  53. int update = st.executeUpdate(sql);
  54. if(update >= 1){
  55. System.out.println("Row is updated.");
  56. }
  57. else{
  58. System.out.println("Row is not updated.");
  59. }
  60. * / }
  61. catch (SQLException s){
  62. System.out.println("SQL statement is not executed!");
  63. }
  64. }
  65. catch (Exception e){
  66. e.printStackTrace();
  67. }
  68. }
  69. }

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

  1. com.jcraft.jsch.JSchException: Auth failApr 18, 2019 4:56:00 PM org.apache.hive.jdbc.Utils parseURL
  2. INFO: Supplied authorities: localhost:4321
  3. Apr 18, 2019 4:56:00 PM org.apache.hive.jdbc.Utils parseURL
  4. INFO: Resolved authority: localhost:4321
  5. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  6. INFO: Transport Used for JDBC connection: null
  7. java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:4321/sahoo: java.net.ConnectException: Connection refused: connect
  8. at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:231)
  9. at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:176)
  10. at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
  11. at java.sql.DriverManager.getConnection(Unknown Source)

暂无答案!

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

相关问题