Java中通过代理连接MySQL
我正在开发一个客户端服务器软件,客户端按如下方式连接到数据库服务器。
...
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", "LA_PASSWORD");
}catch....
...
两个应用程序始终位于同一本地网络上。我遇到的问题是当本地网络使用代理时,在这种情况下MySQL连接失败。
当本地网络上的代理时,如何与 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....
...
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.
How I can make a connection with the Java programming language, a MySQL database when a proxy on the local network?.
Thanks for the help.
Greetings!
尝试使用
socksProxyHost
和socksProxyPort
系统属性。请参阅此处章节“2.4) SOCKS” ” 和 这里。 (http.proxyHost 不适用于 JDBC。)以下是使用 JDBC 代理的说明(例如 Oracle): 通过 JDBC 从内部网连接外部 Internet Oracle 数据库。您可能需要使用以下属性:socksProxySet、socksProxyPort、socksProxyHost、java.net.socks.username、java.net.socks.password、socksNonProxyHosts
。 这里描述如何设置版本、用户名、和密码。而ofc你需要socks代理,而不是HTTP。如果您只有 HTTP 代理,您可以尝试通过 HTTP 建立 JDBC 隧道。解决方案很少。例如,这里是免费解决方案 http://sourceforge.net/projects/sqlgateway/ ,这里是商业解决方案http://www.idssoftware.com/jdbcdrv.html
Try using
socksProxyHost
andsocksProxyPort
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.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