我想从Eclipse连接到SSMS数据库,但是会抛出SQLserverException [英] i want to connect to SSMS database from eclipse but it throws SQLserverException

查看:223
本文介绍了我想从Eclipse连接到SSMS数据库,但是会抛出SQLserverException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Eclipse连接到SSMS数据库。当编译器到达 DriverManager.getConnection(url)行时,它将引发错误。我也启用了TCP / IP,但它给出了错误。

I want to connect to SSMS database from eclipse. when compiler reaches to DriverManager.getConnection(url) line it throws error.I enable TCP/IP also but it giving error.

try{            
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        System.out.println("driver loaded successfully");
        connection= DriverManager.getConnection( "jdbc:sqlserver://localhost\\MSSQLSERVER;user=sa;password=coder182");
        System.out.println("Connection created successfully");
        connection.setAutoCommit( autoCommit);
        statement=connection.createStatement();

        String query ="insert into User_information(name, card_no,amount)" + "values ('"+name+"','"+card_no+"', '"+amount+"');";
        statement.executeUpdate(query);

        System.out.println(query);                      
    }catch(Throwable th){
        th.printStackTrace();
    }           
}

错误:


com.microsoft.sqlserver.jdbc.SQLServerException:与
主机本地主机(名为实例mssqlserver)的连接失败。错误:
java.net.SocketTimeoutException:接收超时。验证
服务器和实例名称,并检查是否没有防火墙阻止UDP
到端口1434的通信。对于SQL Server 2005或更高版本,请验证
SQL Server浏览器服务是否在主机上运行。

com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host localhost, named instance mssqlserver 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.

我想将其连接到数据库。

I want to connect it to database.

推荐答案


  • 打开SQL Server配置管理器

  • SQl服务器网络配置

  • MSSQLSERVER的协议

  • TCP / IP(必须已启用或启用)

  • (双击)

  • IP地址

  • 向下滚动到IPALL

  • 输入端口号1433或1434并保留动态端口为空并应用设置并重新启动服务

    • open SQL Server Configuration Manager
    • SQl Server Network Configuration
    • protocols for MSSQLSERVER
    • TCP/IP(Must be enabled already or enable it)
    • (Double Click)
    • IP Addresss
    • scroll down to IPALL
    • Enter port number 1433 or 1434 and leave dynamic ports empty and apply setting and restart your service
    • 并且您必须指定要连接的数据库名称

      And you must specify databaseName you want to connect

      "jdbc:sqlserver://localhost;instance=MSSQLSERVER;databaseName=name_of_database;user=sa;password=your_password;"
      

      如果问题已解决,则将答案标记为接受

      Mark answer as accepted if issue resolved

      这篇关于我想从Eclipse连接到SSMS数据库,但是会抛出SQLserverException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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