简体   繁体   English

使用JDBC连接到具有防火墙的SQL数据库

[英]Using JDBC to connect to SQL database that has a firewall

I'm currently doing some testing and I want automate some queries of a database. 我目前正在做一些测试,我想自动化数据库的一些查询。 Currently the server I want to connect to has a firewall blocking it so I'm a little confused on how I should set my JDBC and MYSQL Workbench set up. 目前,我要连接的服务器上有防火墙将其阻止,因此我对如何设置JDBC和MYSQL Workbench感到有些困惑。 I'm wondering can anyone give me some advice on what I should be trying to do to successfully connect to the remote DB. 我想知道有人可以给我一些有关成功连接到远程数据库的建议。

JDBC has nothing to do with firewalls or other network related structure. JDBC与防火墙或其他与网络相关的结构无关。 In order to connect properly to the database server, the current computer trying to connect should have access and enough privileges to the database server. 为了正确连接到数据库服务器,当前尝试连接的计算机应具有对数据库服务器的访问权限和足够的特权。 Talk to system administrator or other personal in charge of solving this networking issue. 与系统管理员或其他负责解决此网络问题的人员联系。

First of all, have you attempted connecting to the SQL database? 首先,您是否尝试连接到SQL数据库? If so, do you get an error like 如果是这样,您会收到类似的错误消息吗

SQLServerException: The TCP/IP connection to the host localhost, port (number) has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.

Do you control the server, or have contact with the people who control the server? 您控制服务器,还是与控制服务器的人联系? I had the same problem as you and fixed it by going to the server firewall settings and allowing <port-number> thru the firewall, then set my JDBC connection string as 我遇到了与您相同的问题,并通过转到服务器防火墙设置并允许<port-number>通过防火墙来解决此问题,然后将JDBC连接字符串设置为

 Server=myServerAddress;Port=<port-number>;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

I use SQL Server, not MySQL, but i think it's a matter of ports, and not your database management system. 我使用的是SQL Server,而不是MySQL,但我认为这是端口问题,而不是数据库管理系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM