java - 如何修复“与主机 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();
}
}
解决方案
推荐阅读
- kubernetes - 如何将现有的 git 项目导入具有多个微服务的 Jenkins X?
- direct3d - Direct3D 功能级别是否保证对体积纹理的非 2 次幂支持?
- sed - 在同一表达式侧使用 sed 参数 \1、\2
- c# - 用字典或列表作为值读取 Json 文件 C#
- php - ZipArchive::extractTo 不起作用并且不返回任何内容
- javascript - 开玩笑等到调用 typemoq 函数
- c# - 如何反转打印出的数字
- c# - 具有默认实现的接口和抽象类之间有什么区别?
- r - 将 R 日期值从字符类转换为日期类
- xcode - 查找故事板布局及其相关代码实现的简单方法?