使用Socks的Java JDBC连接 [英] Java JDBC Connection using Socks

查看:197
本文介绍了使用Socks的Java JDBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java,我需要使用JDBC连接到SQL Server数据库.我需要通过我们公司的SOCKS代理,所以我做到了,它似乎起作用了.

Using Java, I need to connect to a SQL Server database using JDBC. I need to go through our companies SOCKS proxy, so I did this and it appeared to work.

Connection conn = null;

Properties systemProperties = System.getProperties();
systemProperties.setProperty("socksProxyHost","socksproxy.domain.com");
systemProperties.setProperty("socksProxyPort","1081");

connectionUrl = "jdbc:sqlserver://1.2.3.4:60304;databaseName=myDatabase;sslProtocol=TLSv1.2;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(connectionUrl,"MyLogin","MyPassword");

但是,我开始看到一些奇怪的东西.该代码在JVM和其他众多应用程序的websphere中运行.

However, I started seeing some odd things. The code is running in websphere in a JVM with numerous other applications.

经过一些测试,似乎更改属性实际上会影响整个JVM.其他连接(LDAP,数据库连接)也在尝试使用我定义的SOCKS代理.

After some testing, it appears changing the properties actually affects the entire JVM. Other connections (LDAP, DB Connections) were also trying to use the SOCKS proxy I defined.

还有另一种方法来强制我的JDBC连接通过不全局的袜子吗?

Is there another way of forcing my JDBC connection to go through socks that isn't global?

推荐答案

这不是最好的解决方案,但是我最终创建了一个用于设置代理主机和端口的独特的JVM.我将使用该JVM来实现需要连接到外部数据库的所有功能.

Not the best solution but I ended up creating a distinct JVM that sets the proxy host and port. I'll use that JVM for any functionality that needs to connect to an external database.

这篇关于使用Socks的Java JDBC连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆