在 Java 中通过代理连接 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6544635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:18:24  来源:igfitidea点击:

MySQL Connect via proxy in Java

javamysqljdbcdatabase-connection

提问by Lobo

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....
...

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.

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

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

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

Thanks for the help. Greetings!

谢谢您的帮助。问候!

回答by zacheusz

Try using socksProxyHostand socksProxyPortsystem properties. Look hereat 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.

尝试使用socksProxyHostsocksProxyPort系统属性。看看这里的章节“2.4)袜子”和这里。(http.proxyHost 不能与JDBC 一起工作。) 下面是使用代理与JDBC 的说明(例如Oracle):从内部网通过JDBC 连接外部互联网Oracle 数据库。您可能想要使用属性:socksProxySet, socksProxyPort, socksProxyHost, java.net.socks.username, java.net.socks.password, socksNonProxyHosts. 下面介绍如何设置版本、用户名和密码。而且你需要socks代理,而不是 HTTP

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

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