gpt4 book ai didi

java - 使用java连接外部数据库

转载 作者:行者123 更新时间:2023-12-01 15:45:57 25 4
gpt4 key购买 nike

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

java.sql.SQLException:网络错误 IOException:远程主机拒绝尝试连接操作。

我正在使用 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 documentation :

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.

我敢打赌,您的防火墙不允许 AIX 主机连接。

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com