Hello Everyone,

I've a problem with java & SQLServer 2005 interface, i installed a SQLServer 2005 and SP2 software bundle to enable
SQLServer to run on Windows Vista, i'm using the "Windows Authentication" in SQLServer 2005 which don't need the
username or password, and i've the classpath to jar archive Microsoft JDBC-ODBC driver, i've used the following
sample code which comes with Microsoft dirver package.

import java.sql.*;

public class connectURL {

public static void main(String[] args) {

    // Create a variable for the connection string.
    String connectionUrl = "jdbc:sqlserver://;" +

    // Declare the JDBC objects.
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

        try {
            // Establish the connection.
                con = DriverManager.getConnection(connectionUrl);

                // Create and execute an SQL statement that returns some data.
                String SQL = "SELECT TOP 10 * FROM Person.Contact";
                stmt = con.createStatement();
                rs = stmt.executeQuery(SQL);

                // Iterate through the data in the result set and display it.
                while (rs.next()) {
                    System.out.println(rs.getString(4) + " " + rs.getString(6));

    // Handle any errors that may have occurred.
    catch (Exception e) {

    finally {
        if (rs != null) try { rs.close(); } catch(Exception e) {}
            if (stmt != null) try { stmt.close(); } catch(Exception e) {}
            if (con != null) try { con.close(); } catch(Exception e) {}

When i tried to run to code above i get the following error:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host,
 port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties 
 and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, 
 and that no firewall is blocking TCP connections to the port. 

So, i absolutly run the SQLServer Manag. Studio, i've checked my IP address, and ports but also have the problem
could someone help me for URGENT.

Thanks in advance :)

Edited by pritaeas: Fixed formatting

8 Years
Discussion Span
Last Post by fuzzyduq

the problem that netbeans can't login to the sql server i mean the server which the required data located in


viva MySQL :)
btw, NetBeans is not having trouble to connect to your database, since NetBeans isn't trying to get connected. the code written in NetBeans might, but I do doubt NetBeans itself would even know that your database exists.



May seem stupid questions, but when you installed SQL Server, did you setup a SQL user the same as your windows user? How have you configured your ODBC correctly? Have you set the network libraries to TCP? Have you set the connection parameter to dynamically select the port?

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.