为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Java 连接到 SQL 服务器时遇到问题

使用 Java 连接到 SQL 服务器时遇到问题

互换的青春 2021-10-20 16:24:21
这是我在代码中编写的内容:Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");String host1 = "<URL/Connection path string>";String uname1= "<User name>";String pwd1 = "<Password>";Connection con1 =DriverManager.getConnection(host1,uname1,pwd1);Statement stmt1 = con1.createStatement();ResultSet rs = stmt1.executeQuery("<Query>");我使用了以下 jar 文件:jtds-1.3.0、sqljdbc-4.1.5605、sqljdbc4-4.0当我运行代码时,出现以下错误:Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host <host-name>, named instance <instance-name> failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.  For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)    at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3589)    at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)    at java.sql.DriverManager.getConnection(DriverManager.java:571)    at java.sql.DriverManager.getConnection(DriverManager.java:215)    at first_doc.main(first_doc.java:28)据我所知,没有阻止流量的防火墙。另外,我是否需要添加端口号作为连接 URL 的一部分?编辑:我使用 SQL 服务器版本 2008我在配置管理器中找不到 SQLEXPRESS 的协议
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 398 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信