在 Java 中通过代理连接 MySQL [英] MySQL Connect via proxy in Java

查看:30
本文介绍了在 Java 中通过代理连接 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个客户端-服务器软件,客户端按如下方式连接到数据库服务器.

I am developing a client-server software, where the client connects to the database server as follows.

...
try
{
   Class.forName("com.mysql.jdbc.Driver");
   Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", "LA_PASSWORD");
}catch....
...

两个应用程序始终位于同一本地网络上.我遇到的问题是当本地网络使用代理时,在这种情况下 MySQL 连接失败.

Both applications are always on the same local network. The problem I have is when the local network uses a proxy, in this case the MySQL connection fails.

当本地网络上的代理时,我如何与 Java 编程语言、MySQL 数据库建立连接?.

How I can make a connection with the Java programming language, a MySQL database when a proxy on the local network?.

感谢您的帮助.问候!

推荐答案

尝试使用 socksProxyHostsocksProxyPort 系统属性.查看此处的2.4) 袜子"一章"和此处.(http.proxyHost 不适用于 JDBC.)以下是使用 JDBC 代理的说明(例如 Oracle):通过JDBC从内网连接外网Oracle数据库.您可能想要使用属性:socksProxySet、socksProxyPort、socksProxyHost、java.net.socks.username、java.net.socks.password、socksNonProxyHosts.这里描述了如何设置版本、用户名、和密码.而且你需要的是socks代理,而不是HTTP.

Try using socksProxyHost and socksProxyPort system properties. Look here at chapter "2.4) SOCKS" and here. (The http.proxyHost will not work with JDBC.) Here is description of use proxy with JDBC (Oracle for example): Connect outside internet Oracle Database from inside intranet through JDBC. You may want to use properties: socksProxySet, socksProxyPort, socksProxyHost, java.net.socks.username, java.net.socks.password, socksNonProxyHosts. Here is description how to set version, username, and password. And ofc you need socks proxy, not HTTP.

如果您只有 HTTP 代理,您可以尝试通过 HTTP 建立 JDBC 隧道.解决方案很少.例如这里是免费的解决方案 http://sourceforge.net/projects/sqlgateway/ 和这里的商业http://www.idssoftware.com/jdbcdrv.html

If you only have HTTP proxy you can try to tunnel JDBC through HTTP. There are few solutions. For example here is free solution http://sourceforge.net/projects/sqlgateway/ and here commercial http://www.idssoftware.com/jdbcdrv.html

这篇关于在 Java 中通过代理连接 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆