Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting data through an SSH tunnel using Hibernate

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 tunnel. Are there any properties which I can use in the hibernate.cfg.xml file to solve this problem? Or may be you can suggest another way which will be understandable to a newbie.

like image 645
Victoria Avatar asked Sep 07 '12 11:09

Victoria


1 Answers

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!

like image 157
BendaThierry.com Avatar answered Sep 22 '22 16:09

BendaThierry.com