using SSH tunnel in Java through jsch, a Java an implementation of SSH2
you have to have an SSH account on the remote host, and for the database example, a database account with a "connect" permission.
在pom.xml中添加
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
需要进入到当前目录含有pom.xml文件的项目中
mvn install
void initDB() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
//
int assigned_port = 0;
try {
JSch jsch = new JSch();
// Create SSH session. Port 22 is your SSH port which is open in your firewall
// setup.
// ssh user:SSH loging username
// ssh password:SSH login password
// ssh host: hostname or ip of SSH server
// ssh port:remote SSH host port number