java到sql server连接异常 [英] java to sql server connectivity exception

查看:142
本文介绍了java到sql server连接异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误/异常 -

I have this error/exception-

SQL异常:com.microsoft.sqlserver.jdbc.SQLServerException:到主机localhost的TCP / IP连接,端口1433失败了。错误:连接超时。验证连接属性,检查主机上是否正在运行SQL Server实例并接受端口上的TCP / IP连接,并且没有防火墙阻止与端口的TCP连接。。

SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".

我的代码是 -

try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String connectionUrl = "jdbc:sqlserver://localhost:1433";
        Connection con = DriverManager.getConnection(connectionUrl,"","");
        System.out.println("ok");
        } catch (SQLException e) {
            System.out.println("SQL Exception: "+ e.toString());
        } 
catch (ClassNotFoundException cE) {
            System.out.println("Class Not Found Exception: "+ cE.toString());
        }

我该如何解决它,请帮助我。

how can i sovle it,please help me.

推荐答案

这几乎可能意味着什么 - 基本上,无法连接到localhost上的端口1433。可能是一个网络问题,可能是数据库没有启动,可能是它正在运行但没有绑定到端口1433.

This could mean almost anything - basically, it was impossible to connect to port 1433 on localhost. Could be a network problem, could be that the database is not started, could be that it is running but not bound to port 1433.

在紧要关头,你可以随时打开一个shell并运行

In a pinch, you can always open a shell and run

telnet localhost 1433

以查看是否可以建立连接。

to see if it is possible to make a connection at all.

这篇关于java到sql server连接异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆