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://127.0.0.1:1433;" +
        "databaseName=msdb;integratedSecurity=true;";

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

        try {
            // Establish the connection.
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                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) {
        e.printStackTrace();
    }

    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 127.0.0.1,
 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 :)

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

even i am facing the almost the same problem.........so pls help me.

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.

Hi,

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.