Results 1 to 5 of 5
  1. #1
    turkuaz07 is offline Member
    Join Date
    Nov 2008
    Posts
    6
    Rep Power
    0

    Default help in java and sql server 2005 interfacing

    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.SQLSer verDriver");
    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 advace

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    800
    Rep Power
    6

    Default

    Hi,
    Just check whether the below link is useful for you.
    SQL Server connection error: Error establishing socket, connection refused
    Last edited by RamyaSivakanth; 05-27-2009 at 11:43 AM.
    Ramya:cool:

  3. #3
    turkuaz07 is offline Member
    Join Date
    Nov 2008
    Posts
    6
    Rep Power
    0

    Default

    Thank you RamyaSivakanth.
    I will try it...

  4. #4
    turkuaz07 is offline Member
    Join Date
    Nov 2008
    Posts
    6
    Rep Power
    0

    Default

    hey RamyaSivakanth...

    I couldnt understand explanations with your link.is there another solution or could u explain me what ı am gonna do step by step...

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    800
    Rep Power
    6

    Default

    Hi,
    Please do the below thing listed in the document.Just put the command mentioned below in ur command prompt.

    For this kind of database connection problem, there are always two distinct issues:
    The SQL server itself is not running or TCP/IP is disabled. That can be confirmed by run



    netstat

    and see it is listed there. And then run

    telnet localhost 1433

    and see it can connect (or whatever port number).

    Even if the server is running, a client program such like jdbc may still fail to connect to it because of a
    firewall

    For testing, you can turn off the XP firewall. And if you have other firewall running, check the firewall log and see any activities that might be related.
    Ramya:cool:

Similar Threads

  1. Connect to SQL server 2005
    By comp in forum JDBC
    Replies: 1
    Last Post: 03-25-2009, 11:25 PM
  2. hibernate support for sql-server 2005
    By javadev in forum JDBC
    Replies: 2
    Last Post: 06-25-2008, 01:48 PM
  3. Replies: 4
    Last Post: 05-21-2008, 06:55 AM
  4. Java connecting to sql server 2005
    By pelegk2 in forum JDBC
    Replies: 0
    Last Post: 04-05-2008, 09:17 PM
  5. SQL Server 2005 Jdbc connection
    By mgt83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-27-2007, 04:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •