Getting data through an SSH tunnel using Hibernate

前端 未结 1 589
花落未央
花落未央 2021-01-03 04:11

I recently started to learn Hibernate technology and have to get data from a database using Hibernate. The problem is that I can connect to the database only via an SSH tunn

相关标签:
1条回答
  • 2021-01-03 04:46

    Maybe using Jsch. Some examples could give you a way to go.

    Another way could be implementing your own SSH SocketFactory, maybe with http proxy handler and port forwarding stuff. A starting point could be:

    SSHSocketFactory fact = new SSHSocketFactory(sshHost, sshPort, new SSHPasswordAuthenticator(sshUser, sshPassword));
    
    sock = fact.createSocket(host, port);
    

    And you could link your implementation with the following parameter inside your hibernate.cfg.xml file:

    hibernate.connection.socketFactory=com.mysql.jdbc.NamedPipeSocketFactory
    

    Or maybe like the way they do here or here (the latter is the better way to go).

    Good ssh stuff!

    0 讨论(0)
提交回复
热议问题