MySQL Connect via proxy in Java

12,782

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

Share:
12,782
Lobo
Author by

Lobo

Software Engineer

Updated on June 05, 2022

Comments

  • Lobo
    Lobo almost 2 years

    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!

  • Gico
    Gico over 6 years
    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?
  • Gico
    Gico over 6 years
    I just found the solution. It is property called socksNonProxyHosts where you may enlist all excluded hosts.