2011-07-12 16 views
0

JDBCを使用してSQL Server 2008 R2とjavaを接続しようとしています。jdbc jarファイルをダウンロードしてeclipseに追加しました.SQL 2008 R2に接続しようとすると、私はSQL側で設定を変更する必要があるかどうかは、デフォルトのポート1433を使用しています。EclipseとSQL Server 2008 R2を接続します

これは私のコードです。

package SocketClient; 

import java.sql.*; 
import com.microsoft.sqlserver.jdbc.*; 

public class SocketClient { 

    public static void main(String[] args) { 

    // Declare the JDBC objects. 
    Connection con = null; 
    CallableStatement cstmt = null; 
    ResultSet rs = null; 

    try { 
    // Establish the connection. 
    SQLServerDataSource ds = new SQLServerDataSource(); 
    ds.setUser("sa"); 
    ds.setPassword("password123"); 
    ds.setServerName("ENMEDIA-EA6278E\\ENMEDIA"); 
    ds.setPortNumber(1433); 
    ds.setDatabaseName("DishTV_Voting"); 
    con = ds.getConnection(); 

    // Execute a stored procedure that returns some data. 
    cstmt = con.prepareCall("{call dbo.uspGetEmployeeManagers(?)}"); 
    cstmt.setInt(1, 50); 
    rs = cstmt.executeQuery(); 

    // Iterate through the data in the result set and display it. 
    while (rs.next()) { 
     System.out.println("EMPLOYEE: " + rs.getString("LastName") + 
      ", " + rs.getString("FirstName")); 
     System.out.println("MANAGER: " + rs.getString("ManagerLastName") + 
      ", " + rs.getString("ManagerFirstName")); 
     System.out.println(); 
    } 
    } 

    // Handle any errors that may have occurred. 
    catch (Exception e) { 
    e.printStackTrace(); 
    } 
    finally { 
    if (rs != null) try { rs.close(); } catch(Exception e) {} 
    if (cstmt != null) try { cstmt.close(); } catch(Exception e) {} 
    if (con != null) try { con.close(); } catch(Exception e) {} 
    System.exit(1); 
    } 
} 
} 

SQLに接続している間、私は取得していますエラーが

ます。com.microsoft.sqlserver.jdbc.SQLServerExceptionです:ホストENMEDIA-EA6278E、ポート1433へのTCP/IP接続が失敗しました。エラー: "接続が拒否されました:connect。接続プロパティを確認し、SQL Serverのインスタンスがホスト上で実行されていることを確認し、TCP/IP接続をポートで受け入れ、ファイアウォールがポートへのTCP接続をブロックしていないことを確認してください。 com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170) com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049) com.microsoft.sqlserver.jdbc。 SQLServerConnection.login(SQLServerConnection.java:833) com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:577) SocketClient.SocketClient.mainでcom.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:57) で(SocketClient.java:23)

私はあなたのスタックトレースでのヒントがブロックされた接続を指している

+0

つまり、本当のパスワードではなく、私は願っていますか? – Wivani

+0

その本物のパスワード – bharathi

+1

そして本番データベース!待って、あなたはソニーの仕事をしていますか? ;-) – Wivani

答えて

2

チェック作業の接続を得ることができます。

0

Connection refused: connect. 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.

のインストールと一緒にJavaを使用したSQLを接続するためのadvance.Anyチュートリアルでwrong.Thanksをどこに行った私を指すanybobyことができます。他の手段(ping、データベースクライアント、telnetなど)で接続できるかどうかを調べるには価値がありますか。データベースを探検するためのEclipseプラグインもあります。あなたはリモート TCP/IP接続を受け入れるために...そこ

乾杯、 ヴィムSQL Serverが(セキュリティ構成を経由して)設定されている場合

関連する問題