gpt4 book ai didi

java - 连接到 Microsoft SQL Server 时出错

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

我尝试从 java 连接到 MS SQL Server 2005,但收到以下错误,谁能帮我吗?

private static final String DRIVER_CLASS = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; 
Class.forName(DRIVER_CLASS);
DriverManager.getConnection("jdbc:sqlserver://localhost:1433","sa","root");

我添加了以下 5 个 jar 文件:

  • 微软数据库
  • mssql服务器
  • msutil
  • sqljdbc
  • sqljdbc4

异常(exception)是:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

最佳答案

你的防火墙打开了吗?如果是这样,也许您需要对端口 1433 进行异常(exception)处理

关于java - 连接到 Microsoft SQL Server 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2199294/

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