簡體   English   中英

Snowflake JDBC 如何檢查主機名/服務器的有效性?

[英]Snowflake JDBC How to check hostname / server validity?

我正在測試我的 Snowflake JDBC 連接,但遇到了一個問題:如何處理無效的 Snowflake 主機名稱?

例如正確的主機名應該是 123abc.us-east-1 但我輸入 123123.us-east-1

這是代碼:

public static Connection getConnection(connectConfigs sfconfig) {
        try {
            Class.forName("com.snowflake.client.jdbc.SnowflakeDriver");
        } catch (ClassNotFoundException ex) {
            System.err.println("Driver not found");
        }

        try {
            // build connection properties
            Properties properties = new Properties();
            properties.put("user", sfconfig.getSfUser());     // replace "" with your username
            properties.put("password", sfconfig.getSfPassword()); // replace "" with your password
            properties.put("account", sfconfig.getSfURL());  // replace "" with your account name
            properties.put("db", sfconfig.getSfDatabase().toUpperCase());       // replace "" with target database name
            properties.put("schema", sfconfig.getSfSchema().toUpperCase());   // replace "" with target schema name
            properties.put("loginTimeout", 30);
            //properties.put("tracing", "on");

            // create a new connection
            String connectStr = System.getenv("SF_JDBC_CONNECT_STRING");

            // use the default connection string if it is not set in environment
            if (connectStr == null) {
                connectStr = "jdbc:snowflake://" + sfconfig.getSfURL() + ".snowflakecomputing.com"; // replace accountName with your account name
            }
            return DriverManager.getConnection(connectStr, properties);
        } catch (SQLException e) {
            System.err.println("some error here");
        }
        return null;
    }

如果我提供了無效的主機名,所有這些都會打印到控制台:

May 24, 2021 4:34:05 PM net.snowflake.client.jdbc.RestRequest execute
SEVERE: Stop retrying since elapsed time due to network issues has reached timeout. Elapsed: 69,280(ms), timeout: 60,000(ms)
May 24, 2021 4:34:05 PM net.snowflake.client.jdbc.RestRequest execute
SEVERE: Error response: HTTP Response code: 403, request: POST https://123123.us-east-1.snowflakecomputing.com:443/session/v1/login-request?databaseName=TEST_CONNECT&schemaName=FRIEND&requestId=b4c13959-cbbf-45b8-acf6-f758176545e5 HTTP/1.1
May 24, 2021 4:34:05 PM net.snowflake.client.core.HttpUtil executeRequestInternal
SEVERE: Error executing request: POST https://123123.us-east-1.snowflakecomputing.com:443/session/v1/login-request?databaseName=TEST_CONNECT&schemaName=FRIEND&requestId=b4c13959-cbbf-45b8-acf6-f758176545e5 HTTP/1.1
May 24, 2021 4:34:05 PM net.snowflake.client.jdbc.SnowflakeUtil logResponseDetails
SEVERE: Response status line reason: Forbidden
May 24, 2021 4:34:05 PM net.snowflake.client.jdbc.SnowflakeUtil logResponseDetails
SEVERE: Response content: <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
</body>
</html>

我怎樣才能優雅地處理這個而不是把這個巨大的混亂打印到控制台?

提前謝謝!

將這一行添加到連接屬性解決了我的問題。

properties.put("tracing", "OFF");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM