【问题标题】:Can't connect to SQL Server using JDBC无法使用 JDBC 连接到 SQL Server
【发布时间】:2018-05-20 03:04:48
【问题描述】:

我在使用 Netbeans 中的 JDBC 驱动程序连接到数据库服务器时遇到问题。我已经尝试了一切,启用 TCP/IP,打开端口,我已经按照在线教程进行操作。它只是行不通。

这是我在控制台中收到的错误消息:

Information: Error: The TCP / IP connection could not be made to the MANUEL-PC host, port 1433. Error: "Connection refused: connect Verify the connection properties, check that there is an instance of SQL Server running on the host and accepting TCP / IP connections on the port and verify that there is no firewall blocking TCP connections on the port. "

我们正在使用的类的开始...

 public class DBPosteo
{
    private final String URL ="jdbc:sqlserver://MANUEL-PC\\SQLEXPRESS:1433;databaseName=DLC_MotorDeBusqueda;integratedSecurity=true"; 


    private Connection con;
    String query = "";
    PreparedStatement pstmt;
    ResultSet rs;

    public void init()
            throws ClassNotFoundException, SQLException
    {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        con = DriverManager.getConnection(URL);
    }

DB Server name in SQL Management Studio

在此先感谢您的帮助...我这辈子从未在数据库方面如此挣扎:)

【问题讨论】:

    标签: java sql-server jdbc netbeans


    【解决方案1】:

    删除端口号

    仅指定实例名称 (SQLEXPRESS) 端口号 (1433),切勿同时指定两者。

    由于端口 1433 是为未命名实例保留的,因此 SQLEXPRESS 命名实例将位于不同的端口上,除非您专门配置它(不太可能),否则该端口是动态的并且可以在重新启动时更改,因此您需要命名查找。

    【讨论】:

    • 成功了!非常感谢...过去2个小时我做了很多配置设置,答案很简单!以后我会毫不犹豫地再问这里...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 2013-02-03
    • 1970-01-01
    相关资源
    最近更新 更多