snowflakedb / snowflake-jdbc

Snowflake JDBC Driver
Apache License 2.0
178 stars 170 forks source link

SNOW-965692: jdbc connector doesn't work for private link #1555

Closed scardena closed 1 year ago

scardena commented 1 year ago

Please answer these questions before submitting your issue. In order to accurately debug the issue this information is required. Thanks!

  1. What version of JDBC driver are you using? snowflake-jdbc-3.14.3.jar

  2. What operating system and processor architecture are you using? Amazon linux

  3. What version of Java are you using?

    java --version
    openjdk 11.0.20 2023-07-18 LTS
    OpenJDK Runtime Environment (Red_Hat-11.0.20.0.8-1.amzn2.0.1) (build 11.0.20+8-LTS)
    OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.0.8-1.amzn2.0.1) (build 11.0.20+8-LTS, mixed mode, sharing)
  4. What did you do? Trying to connect to snowflake using jdbc, fails for private link. This is the code I am using:

    public class SnowflakeJDBCExample {
    
    public static void main(String[] args) {
    
        # I replaced the actual endpoint with blabla as it might be sensitive. i didn't actually use blabla as the endpoint. I also modified the error message below for consistency purposes.
        String url = "jdbc:snowflake://app-blabla.privatelink.snowflakecomputing.com/?db=mydb";
        String user = "myuser";
        String password = "mypass";
    
        try {
            // Load the Snowflake JDBC driver
            Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
    
            // Create a connection to Snowflake
            Connection connection = DriverManager.getConnection(url, user, password);
    
            // Create and execute an SQL query
            Statement statement = connection.createStatement();
            String sqlQuery = "SELECT * FROM mytable";
            ResultSet resultSet = statement.executeQuery(sqlQuery);
    
            // Process the query results
            while (resultSet.next()) {
                // Retrieve and print data from the result set
                String columnName = resultSet.getString("my_column");
                System.out.println("Column Name: " + columnName);
            }
    
            // Close the result set, statement, and connection
            resultSet.close();
            statement.close();
            connection.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
    }

    but I a getting the following error when running this:

    
    ava -cp /tmp:/tmp/snowflake-jdbc-3.14.3.jar SnowflakeJDBCExample
    Nov 09, 2023 2:39:19 PM net.snowflake.client.jdbc.RestRequest execute
    SEVERE: Error response: HTTP Response code: 405, request: POST https://app-blabla.privatelink.snowflakecomputing.com/?db:443/session/v1/login-request?databaseName=mydb&requestId=5e560a81-0264-4790-9a26-6a77d8758633 HTTP/1.1
    Nov 09, 2023 2:39:19 PM net.snowflake.client.core.HttpUtil executeRequestInternal
    SEVERE: Error executing request: POST https://app-blabla.privatelink.snowflakecomputing.com/session/v1/login-request?databaseName=mydb&requestId=5e560a81-0264-4790-9a26-6a77d8758633 HTTP/1.1
    Nov 09, 2023 2:39:19 PM net.snowflake.client.jdbc.SnowflakeUtil logResponseDetails
    SEVERE: Response status line reason: Method Not Allowed
    Nov 09, 2023 2:39:19 PM net.snowflake.client.jdbc.SnowflakeUtil logResponseDetails
    SEVERE: Response content: <html>
    <head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>

net.snowflake.client.jdbc.SnowflakeSQLException: JDBC driver encountered communication error. Message: HTTP status=405. at net.snowflake.client.core.HttpUtil.executeRequestInternal(HttpUtil.java:781) at net.snowflake.client.core.HttpUtil.executeRequest(HttpUtil.java:684) at net.snowflake.client.core.HttpUtil.executeGeneralRequest(HttpUtil.java:601) at net.snowflake.client.core.SessionUtil.newSession(SessionUtil.java:631) at net.snowflake.client.core.SessionUtil.openSession(SessionUtil.java:298) at net.snowflake.client.core.SFSession.open(SFSession.java:524) at net.snowflake.client.jdbc.DefaultSFConnectionHandler.initialize(DefaultSFConnectionHandler.java:112) at net.snowflake.client.jdbc.DefaultSFConnectionHandler.initializeConnection(DefaultSFConnectionHandler.java:85) at net.snowflake.client.jdbc.SnowflakeConnectionV1.initConnectionWithImpl(SnowflakeConnectionV1.java:116) at net.snowflake.client.jdbc.SnowflakeConnectionV1.(SnowflakeConnectionV1.java:96) at net.snowflake.client.jdbc.SnowflakeDriver.connect(SnowflakeDriver.java:206) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at SnowflakeJDBCExample.main(SnowflakeJDBCExample.java:21)



5. What did you expect to see?

the results of the query. using the public snowflake endpoint works fine, so the code works. i assume this is no private link issue, due to getting a 405 instead of a time out or something else networking related.

6. Can you set logging to DEBUG and collect the logs?

  Logs don't seem to be showing any more interesting data than the error message. I can provide those if needed
   https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors

7. What is your Snowflake account identifier, if any? (Optional)
scardena commented 1 year ago

I noticed I was using the app- endpoint, but I should be using the endpoint without that prefix.