Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Java program establish JDBC Connection via Proxy Server

Tags:

java

proxy

jdbc

I want to communicate to Oracle DB Server which sits outside my network via the proxy server. I can access the web application hosted on the same machine via Browser with proxy settings. Can a simple Java program establish JDBC Connection thru the proxy server?

*To provide an example will be better *

Regards.

like image 341
爱国者 Avatar asked Sep 13 '12 11:09

爱国者


2 Answers

If the proxy is only a HTTP proxy, then no. But if the proxy transfers TCP/IP trafic, then you can.

How to do that, look at How do I set the proxy to be used by the JVM or http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

like image 146
kovica Avatar answered Sep 28 '22 04:09

kovica


Oracle JDBC (and any other JDBC connections to that extent) are not HTTP-based protocols, so the proxying has to be done at TCP layer.

For this reason, you can't use Squid Proxy for example (which only does proxying at HTTP layer), but there are many other proxying services that can work at TCP layer:

  • nginx proxy
  • haproxy

On the former there is a nice step by step guide how to setup JDBC proxying using NGINX https://kwjrnl.wordpress.com/2015/07/27/tcp-proxy-with-nginx-for-jdbc-connection/

like image 39
Tagar Avatar answered Sep 28 '22 03:09

Tagar