首页 > 解决方案 > 如何修复“与主机 localhost、端口 1433 的 TCP/IP 连接失败。”

问题描述

与主机 localhost 端口 1433 的 TCP/IP 连接失败。错误:“连接被拒绝:连接。验证连接属性。确保 SQL Server 实例正在主机上运行并在端口接受 TCP/IP 连接。确保与端口的 TCP 连接未被防火墙阻止."。

这适用于 java netbeans 8.2 版本并运行 sql server 17。我在现有服务器上进行了尝试,但似乎总是不得不与主机 localhost 建立 TCP/IP 连接,端口 1433 失败。以下代码::::

private void signin1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        user= username.getText().trim();
        pass= password.getText().trim();

        try{ 

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
    Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=xyz;integratedSecurity=true");  

     Statement statement = connection.createStatement();  

 ResultSet resultSet = statement.executeQuery(" select id, password from signin where username='"+user+"' and password='"+pass+"' ");  


  if(resultSet.next()){

           new NewJFrame().setVisible(true);
                this.setVisible(false);
            }

         } catch (ClassNotFoundException | SQLException e) {  
             e.printStackTrace();  
         }  
    }

标签: javasql-servertcpsqlconnection

解决方案


推荐阅读