I tried connect to Oracle DB in java but i faced error and i search many time i didn't find thing help me.
when i tried to connect using SQL developer its success.
so i tried write java code to access the DB its success connect to SSH but i faced error when reaches conn = DriverManager.getConnection:
"java.sql.SQLException: Io exception: Oracle Error ORA-12650"
This is my function
public static Connection sshTunel() {
String sshHost = "sshHost";
String sshuser = "sshUser";
String SshKeyFilepath =
"pathOfKey";
Session session;
int localPort = 22;
String remoteHost = "HostIp";
int remotePort = 1521;
String usr = "DB user";
String pwd = "DB pass";
try {
java.util.Properties config = new java.util.Properties();
JSch jsch = new JSch();
session = jsch.getSession(sshuser, sshHost, 22);
jsch.addIdentity(SshKeyFilepath, "ssh Pass");
config.put("StrictHostKeyChecking", "no");
config.put("Compression", "yes");
config.put("ConnectionAttempts", "2");
session.setConfig(config);
session.connect();
System.out.println("SSH Connected ...");
int assinged_port =
session.setPortForwardingL(localPort, remoteHost, remotePort);
System.out.println("localhost:" + assinged_port + " -> " +
remoteHost + ":" + remotePort);
System.out.println("Port Forwarded ...");
try {
Class.forName("oracle.jdbc.pool.OracleDataSource");
conn =
DriverManager.getConnection("jdbc:oracle:thin:@remoteHost:1521/SID",
"DB User", "DB Pass");
} catch (SQLException ex) {
ex.printStackTrace();
System.out.println("Error in connection");
}
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}


remoteHost:1521rather thanlocalhost:<assigned_port>? I'm a bit confused that you say SQL Developer connects - is that directly or also via SSH?setPortForwardingLbeforeconnect?