Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Connect via proxy in Java

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!

like image 921
Lobo Avatar asked Jul 01 '11 06:07

Lobo


1 Answers

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

like image 200
zacheusz Avatar answered Oct 03 '22 04:10

zacheusz