java - 通过telnet连接外部数据库

标签 java unix telnet jtds

我有一个连接到 MS SQL 数据库的 java 程序。该程序在通过 eclipse 运行时完美工作,但是当我通过 AIX 运行它时出现错误:

java.sql.SQLException: Network error IOException: A remote host refused an attempted connect operation.

我可以成功 ping 服务器,但无法 telnet 到服务器。我也无法从 Windows 桌面远程登录。

我正在使用 jtds 进行连接:

String connectionString = "jdbc:jtds:sqlserver://"+dropez_ip_address+"/"+dropez_db_name;
ResultSet rs = null;
Statement stmt = null;

try{

    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection conn = DriverManager.getConnection(connectionString, dropez_db_username, dropez_db_password);

    stmt = conn.createStatement();
}catch(Exception e){}

这是 jTDS 提供的有关该问题的一些文档,但我仍然无法解决该问题。

Why do I get java.sql.SQLException: "Network error IOException: Connection refused: connect" when trying to get a connection?

The "Connection refused" exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:

    - The server name is misspelled or the port number is incorrect.
    - SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
    - There is a firewall blocking port 1433 on the server.

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.

最佳答案

如果您无法在端口 1433 上进行 telnet,则说明您被计算机和服务器之间的防火墙阻止了。这不是 java 相关的问题。

当你说“它在 Eclipse 下运行完美,但在 AIX 下运行不完美”时,你可能正在使用大约 2 台不同的计算机吗?如果是这样,则带有 eclipse 的防火墙未受防火墙保护,您部署应用程序的防火墙已被阻止。

但是,与 java 无关。这是 TCP-IP 模型的 3 级错误(TCP 层)。

问候, 史蒂芬

关于java - 通过telnet连接外部数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7014312/

相关文章:

java - 如何将数据绑定(bind)到 spring 表单中的列表

java - 我的应用程序在尝试使用 Volley 时崩溃

c - 如何离开(中断)waitpid()函数?

python - 多个同时网络连接 - Telnet 服务器,Python

HTTP 请求 - 永久移动?

java - bufferedImage.getRGB(x, y) 不产生 alpha

java - 将 XML 从网站解析到 Android 设备

linux - 去除转义字符的 ASCII 文本(ls 输出重定向)

对管道实现感到困惑

authentication - Telnet 自动化与 Expect : Slow authentication?