2016-09-23 5 views
3

JDBC를 통해 Azure SQL 데이터웨어 하우스에 연결하려고합니다. 다음과 같은 예외가 발생합니다.JDBC를 사용하여 Azure SQL 데이터웨어 하우스에 연결하는 중 SQLException이 발생했습니다.

*

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host tcsqldatawh.database.windows.net, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". 
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191) 
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242) 
    at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2280) 
    at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:493) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1387) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451) 
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014) 
    at java.sql.DriverManager.getConnection(DriverManager.java:664) 
    at java.sql.DriverManager.getConnection(DriverManager.java:270) 
    at testsqldw.SQLDatabaseConnection.main(SQLDatabaseConnection.java:30) 

* 나는 SQLServer에 DB here 연결에 대한 질문과 비슷한 질문을 본

.

here 프로세스를 사용하여 내 IP에 대한 액세스를 허용하도록 데이터베이스를 구성했습니다.

확인하시기 바랍니다 아래 코드 : SQLSERVER : //databaseserver.database.windows.net :

package testsqldw; 

import java.sql.*; 

    public class SQLDatabaseConnection { 

     // Connect to your database. 
     // Replace server name, username, and password with your credentials 
     public static void main(String[] args) { 


      String connectionString = 
        "jdbc:sqlserver://databaseserver.database.windows.net:1433;" 
        +"database=databaseserver;" 
        +"[email protected];" 
        + "password=password;" 
        + "encrypt=true;" 
        + "trustServerCertificate=false;" 
        + "hostNameInCertificate=*.database.windows.net;" 
        + "loginTimeout=30;"; 

      System.out.println("Total connection string is---\n"+connectionString); 

      // Declare the JDBC objects. 
      Connection connection = null; 
      Statement statement = null; 
      ResultSet resultSet = null; 

      try { 
       connection = DriverManager.getConnection(connectionString); 

       // Create and execute a SELECT SQL statement. 
       String createSql = "create table employee(employee_id varchar(20));"; 
       statement = connection.createStatement(); 
       boolean status=statement.execute(createSql); 

       System.out.println(status); 

       // Print results from select statement 

      } 
      catch (Exception e) { 
       e.printStackTrace(); 
      } 
      finally { 
       // Close the connections after the data has been handled. 

       if (statement != null) try { statement.close(); } catch(Exception e) {} 
       if (connection != null) try { connection.close(); } catch(Exception e) {} 
      } 
     } 
    } 

총 연결 문자열

JDBC이다 1433; 데이터베이스 = databaseserver; 사용자 = 사용자 이름 @databaseserver; password = password; encrypt = true; trustServerCertificate = false; hostNameInCertificate = *. database.windows.net; loginTimeout = 30;

문제를 해결하는 데 도움을주십시오. 내 경험 당

답변

1

이 문제는 다음과 같은 이유로 인해 발생할 수 있습니다

  1. 당신이 잘 작동하지 않을 수 있습니다 생성 한 SQL 서버.
  2. 잘못된 JDBC 연결 문자열을 사용할 수 있습니다.

첫째, 일부 클라이언트 도구를 사용하여 SQL 서버에 연결할 수 있습니다. 서버에 연결할 수 있으면 SQL 서버가 정상임을 나타냅니다. 그렇지 않으면 새 SQL Server를 만들 수 있습니다. 그 후에이 URL https://azure.microsoft.com/en-us/documentation/articles/sql-data-warehouse-get-started-provision/에 따라 새 SQL 데이터웨어 하우스를 만들 수 있습니다. URL에는 방화벽 구성 방법도 포함됩니다.

SQL Server에 연결할 때 InTouch를 사용합니다. 다음은 몇 가지 설명 이미지입니다.

enter image description here

당신은 푸른 포털에 의해 매개 변수를 얻을 수 있습니다. 포트 번호는 1433입니다.

다음 그림은 서버가 정상임을 나타냅니다.

enter image description here

는 두 번째 이유를 들어, 푸른 포털에서 연결 문자열을 복사하여 암호 만 수정할 수 있습니다.

enter image description here

는 도움이되기를 바랍니다. 우려 사항이 있으시면 언제든지 알려주세요.

관련 문제