flex_grigorowicz
flex_grigorowicz

Reputation: 63

jdbc.SQLServerException when i tried to connect database

I have class for connecting to DB from my JavaFx application

public class DBConnection {

public static Connection mcConnection() {
    Connection connection = null;
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String url = "jdbc:sqlserver://localhost; databaseName=McQueen_db;";
        connection = DriverManager.getConnection(url);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return connection;
}

}

When i tried to connect i have an exception

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host port 1433 has failed. Error: "null. 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.".

I check my firewall and its ok. I think that port too. Have any thoughts whats the problem?

Upvotes: 0

Views: 133

Answers (1)

Qingfei Yuan
Qingfei Yuan

Reputation: 1212

try to change "localhost" to "127.0.0.1"

As sometimes, your system cannot mapping localhost correctly.

refer to official doc

Upvotes: 1

Related Questions