Liam Donnellan
Liam Donnellan

Reputation: 13

Can ojdbc connect to an Oracle database via a SOCKS proxy?

I am trying to connect to an oracle database using the ojdbc driver via a SOCKS proxy. I cannot find a definitive answer online as to whether this should work or not.

Does Oracle jdbc driver support SOCKS5 proxy? seems to suggest that the 18.1 release should have added SOCKS proxy support, but, using ojdbc8-18.3, the driver doesn't seem to honour the proxy settings and the latest documentation makes no mention of it.

Here is analogous code to that which I have tried (database details redacted).

System.setProperty("socksProxyHost", "myProxy");
System.setProperty("socksProxyPort", "1080");
Class.forName("oracle.jdbc.driver.OracleDriver");

try (
    Connection con = DriverManager.getConnection(
        "jdbc:oracle:thin:@myServer:1521/mySID", "myUser", "myPwd"
    );
)
{
    Statement stmt=con.createStatement();

    ResultSet rs=stmt.executeQuery(" select * from my_table ");
    while(rs.next())
        System.out.println(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getInt(3));
​
} 
catch (Exception e)
{
            System.out.println(e);
}

In this case, the connection succeeds, but when I use Wireshark to check the outgoing traffic, I can see that the connection is made directly. I can further verify this by changing the proxy settings to...

System.setProperty("socksproxyHost", "should not resolve");
System.setProperty("socksproxyPort", "1080");

...and observing that the connection is still made and data is returned.

When doing the same thing with Microsoft SQL Server driver, I see the following error:

SQLServerException: The TCP/IP connection to the host , port 1433 has failed. Error: "Can't connect to SOCKS proxy:shouldnotresolve.

This is obviously specific to SQL Server, but I expected to see something similar for Oracle.

Upvotes: 1

Views: 3355

Answers (2)

Fabian Henze
Fabian Henze

Reputation: 997

To enable socks proxy support in the oracle JDBC driver, you need to pass -Doracle.jdbc.javaNetNio=false to JVM or set the property accordingly in your code.

Upvotes: 5

Andreas
Andreas

Reputation: 159086

Does Oracle jdbc driver support SOCKS5 proxy? seems to suggest that the 18.1 release should have added SOCKS proxy support

I don't see how you're getting that, given that it said:

No the Oracle JDBC driver doesn't support SOCKS5 proxy. In the soon to be release 18.1 version of the thin driver there will be support for HTTPS proxy and websocket.


the latest documentation makes no mention of it

Sure it does, see the Oracle® Database, JDBC Developer's Guide, Release 18c.
Specifically section 8.2.2 Support for HTTPS Proxy Configuration.

Upvotes: 1

Related Questions