Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过SSH隧道连接到jdbc中的oracle db_Jdbc_Ssh - Fatal编程技术网

通过SSH隧道连接到jdbc中的oracle db

通过SSH隧道连接到jdbc中的oracle db,jdbc,ssh,Jdbc,Ssh,目前,我们必须通过SSH隧道来访问Oracle数据库。为了做到这一点,我们必须确保在将应用程序部署到Tomcat/Glassfish/etc之前,服务器上正在运行than putty或等效的程序/脚本进行此调优 有没有人找到让java透明地处理这个隧道的方法?也许是一个jdbc驱动程序本身包装了另一个jdbc驱动程序,用Java为您处理隧道?不久前,我在一个项目中使用了ApacheMina SSHD,我记得有人支持R打开隧道 你可以查看更多信息 在这个问题上讨论了其他选项:我的解决方案是在我的应

目前,我们必须通过SSH隧道来访问Oracle数据库。为了做到这一点,我们必须确保在将应用程序部署到Tomcat/Glassfish/etc之前,服务器上正在运行than putty或等效的程序/脚本进行此调优


有没有人找到让java透明地处理这个隧道的方法?也许是一个jdbc驱动程序本身包装了另一个jdbc驱动程序,用Java为您处理隧道?

不久前,我在一个项目中使用了ApacheMina SSHD,我记得有人支持R打开隧道

你可以查看更多信息


在这个问题上讨论了其他选项:

我的解决方案是在我的应用服务器启动时使用JCraft的Jsch打开一个隧道。当应用服务器关闭时,我关闭隧道。我通过servlet上下文侦听器来实现这一点

int findUnusedPort() {
        final int startingPort = 1025;
        final int endingPort = 1200;
        for (int port = 1025; port < 1200; port++) {
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(port);
                return port;
            } catch (IOException e) {
                System.out.println("Port " + port + "is currently in use, retrying port " + port + 1);
            } finally {
                // Clean up
                if (serverSocket != null) try {
                    serverSocket.close();
                } catch (IOException e) {
                    throw new RuntimeException("Unable to close socket on port" + port, e);
                }
            }
        }
        throw new RuntimeException("Unable to find open port between " + startingPort + " and " + endingPort);
    }

private Session doSshTunnel(int tunnelPort) {
    // SSH Tunnel
    try {
        final JSch jsch = new JSch();
        sshSession = jsch.getSession("username", "sshhost", 22);
        final Hashtable<String, String> config = new Hashtable<String, String>();
        config.put("StrictHostKeyChecking", "no");
        sshSession.setConfig(config);
        sshSession.setPassword("password");

        sshSession.connect();

        int assigned_port = sshSession.setPortForwardingL(tunnelPort, remoteHost, remotePort);

        return sshSession;
    } catch (Exception e) {
        throw new RuntimeException("Unable to open SSH tunnel", e);
    }
} 
int findUnusedPort(){
最终int启动端口=1025;
最终int endingPort=1200;
用于(int端口=1025;端口<1200;端口++){
ServerSocket ServerSocket=null;
试一试{
serverSocket=新的serverSocket(端口);
返回端口;
}捕获(IOE异常){
System.out.println(“端口“+端口+”当前正在使用,正在重试端口“+端口+1”);
}最后{
//清理
如果(serverSocket!=null),请尝试{
serverSocket.close();
}捕获(IOE异常){
抛出新的RuntimeException(“无法关闭端口上的套接字”+端口,e);
}
}
}
抛出新的RuntimeException(“无法在“+startingPort+”和“+endingPort”之间找到打开的端口);
}
专用会话doSshTunnel(内部隧道端口){
//SSH隧道
试一试{
最终JSch JSch=新JSch();
sshSession=jsch.getSession(“用户名”,“sshhost”,22);
final Hashtable config=new Hashtable();
配置放置(“检查”、“否”);
sshSession.setConfig(config);
sshsSession.setPassword(“密码”);
sshSession.connect();
int assigned_port=sshSession.setPortForwardingL(隧道端口、远程主机、远程端口);
返回SSH会话;
}捕获(例外e){
抛出新的RuntimeException(“无法打开SSH隧道”,e);
}
}