This is the Putty image:
I tried to connect to my Putty and was able to connect, then trying to connect to Hive with JDBC, but still facing the same connection issue. Here's my code.
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();
}
}
}
After this I got this message. Although I'm not aware of the Lport, what to use exactly for Hive.
This is the error report:
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)