11

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!

3
  • 3
    What do you mean "the local network uses a proxy" ? Do you mean an HTTP proxy? MySQL uses a binary protocol not HTTP. Is the connection being blocked by a firewall? Commented Jul 1, 2011 at 8:20
  • Yes, i mean an HTTP PROXY. Thanks. Commented Jul 14, 2011 at 16:27
  • @Lobo your proxy required authentification by user & psw ??? Commented Jul 14, 2011 at 17:57

1 Answer 1

21
+50

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.

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the answer. The provided solution will redirect all the traffic over the socksProxyHost. In my case i have two DB connections. One should go through proxy and one is on the local network. Any suggestion how to handle this?
I just found the solution. It is property called socksNonProxyHosts where you may enlist all excluded hosts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.