java - 如何使用 JDBC 修复 SQL 服务器中的端口 1433 失败错误,我尝试了所有方法

标签 java sql-server eclipse jdbc port

所以我尝试在 Java 中使用 Eclipse 和 SQL Server 2014 进行 UDT:

这是我将 SQL 服务器连接到 eclipse 的代码部分,我已经将 JDBC jar 安装到了该路径。

Connection con = null;   PreparedStatement statement = null; //to take care of the sql statements to be run  
         //Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

         con = DriverManager.getConnection("jdbc:sqlserver://localhost‌​;databaseName=Company;integratedSecurity=true;");
         //con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433‌​;databaseName=MASTER‌​;user=sa;password=Se‌​cret");

这是我的错误输出,虽然我还没有在 SQL Server 中创建表,但我想尝试看看 Eclipse 是否连接到 SQL Server 2014,到目前为止这是我的错误:

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost‌​, port 1433 has failed. Error: "localhost‌​. 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.".
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)
    at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242)
    at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2369)
    at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:551)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1963)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at insertion.insert_values(insertion.java:12)
    at PointType.main(PointType.java:65)

不用担心我的插入部分,我只是想知道为什么我的端口连接失败?

我尝试了所有方法,但到目前为止仍然无法连接,可能是什么原因造成的?

最佳答案

您的 URL 中的“localhost”拼写错误

关于java - 如何使用 JDBC 修复 SQL 服务器中的端口 1433 失败错误,我尝试了所有方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42988758/

相关文章:

java - 当只有一个类变量的副本在该特定类的所有实例之间共享时,为什么会出现 "reinitialise the class variable"

sql-server - 我有一个带有 UNION 的 SQL View ,当通过 Entity Framework 使用时,结果是错误的。为什么?

java - Eclipse Java printf 问题 PrintStream 不适用

java - 如何将Java接口(interface)代码移植到C++抽象基类中?

java - HTTP 状态 404 -/FirstServlet/test

java - 可以使用 InterfaceBasedMBeanInfoAssembler 为 Spring JMX MBean 设置描述吗?

SQL Server : alter column with fix value

sql-server - 仅当最近时才从暂存插入到最终

eclipse - Eclipse 中未定义的属性名称(ng-model)

linux - 从 eclipse 将更改提交到 cvs