java.sql.Connection extension for SSH

霸气de小男生 提交于 2019-12-18 11:55:23

问题


I have a MySQL database behind a firewall which can only be accessed via an SSH connection. Does anyone know of an implementation of java.sql.Connection which would allow me to make an SSH connection to this database?


回答1:


You can use SSH's port forwarding to do this. While not a pure java.sql.Connection, it will allow you to tunnel the connection through ssh.

ssh -L 3306:localhost:3306 remote.mysql.host.com

This will forward port 3306 on your local machine to port 3306 on remote.mysql.host.com. This will allow you to connect to port 3306 on your local machine, and it will be tunnelled to remote.mysql.host.com.

If you're looking to do it all in Java, create the ssh connection with JSch.




回答2:


Here is an example using the library sshj.



来源:https://stackoverflow.com/questions/252258/java-sql-connection-extension-for-ssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!