另一种方式可能是实现自己的SSH SocketFactory,也许使用http代理处理程序和端口转发的东西。一个起点可能是: $ p $ SSHSocketFactory fact = new SSHSocketFactory(sshHost,sshPort,new SSHPasswordAuthenticator(sshUser,sshPassword)); sock = fact.createSocket(host,port);
您可以将您的实现与 hibernate.cfg中的以下参数关联.xml file:
hibernate.connection.socketFactory = com.mysql.jdbc.NamedPipeSocketFactory或者像他们一样此处或这里(后者是更好的方式)
良好的ssh文件!
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.
解决方案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.NamedPipeSocketFactoryOr maybe like the way they do here or here (the latter is the better way to go).
Good ssh stuff!
更多推荐
使用Hibernate通过SSH隧道获取数据
发布评论