使用Hibernate通过SSH隧道获取数据

编程入门 行业动态 更新时间:2024-10-27 18:18:09
本文介绍了使用Hibernate通过SSH隧道获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 最近我开始学习Hibernate技术,并且必须使用Hibernate从数据库获取数据。问题是我只能通过SSH隧道连接到数据库。有没有我可以在 hibernate.cfg.xml 文件中使用的任何属性来解决这个问题?或者可能是你可以建议另一种新手会理解的方式。

//www.jcraft/jsch/rel =nofollow> Jsch 。 一些例子可能会给你一条路。

另一种方式可能是实现自己的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.NamedPipeSocketFactory

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

Good ssh stuff!

更多推荐

使用Hibernate通过SSH隧道获取数据

本文发布于:2023-10-07 12:37:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:隧道   数据   Hibernate   SSH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!