所以我尝试在 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=Secret");
这是我的错误输出,虽然我还没有在 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/