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

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

问题描述

我正在开发一个客户端 - 服务器软件,客户端连接到数据库服务器,如下所示。

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

在同一本地网络上。我的问题是当本地网络使用代理,在这种情况下MySQL连接失败。



如何使用Java编程语言连接,MySQL数据库当一个代理在本地网络?。



感谢您的帮助。

解决方案

尝试使用 socksProxyHost socksProxyPort 系统属性。请查看此处的2.4)SOCKS和此处。 (http.proxyHost将不能使用JDBC。)下面是使用JDBC的代理(例如Oracle)的描述:从内部网通过JDBC连接外部Internet数据库。您可能想要使用属性: socksProxySet,socksProxyPort,socksProxyHost,java.net.socks.username,java.net.socks.password 以下是说明如何设置版本,用户名和密码。 如果您只有HTTP代理,您可以尝试通过HTTP隧道传输JDBC。 有几个解决方案。例如,这里是免费的解决方案 http://sourceforge.net/projects/sqlgateway/ 和这里的商业< a href =http://www.idssoftware.com/jdbcdrv.html =noreferrer> http://www.idssoftware.com/jdbcdrv.html


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!

解决方案

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

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

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