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