Matthew
Matthew

Reputation: 867

No suitable driver found snowflake JDBC

I'm currently working on an application. We are moving off our file systems and over to our Snowflake database. I can't seem to make a connection to the database - I am continually met with "no suitable driver found" error.

The correct driver was loaded and installed into the build path. Does anyone know whats going on?

The code:

package com.GriefUI.DBComponents;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class Snowflake_Driver {

public static void databaseConnection(HttpServletRequest request, HttpServletResponse response) throws UnsupportedOperationException{


    try {

        Connection connObject = getConnection();
        Statement stmt = connObject.createStatement();
        ResultSet rSet = stmt.executeQuery("SELECT * FROM MY_TABLE");


    }catch(Exception e) {
        e.printStackTrace();
        throw new UnsupportedOperationException();
    }

}


 private static Connection getConnection()
          throws SQLException {
        try {
          Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
        } catch (ClassNotFoundException ex) {
          System.err.println("Driver not found");
        }

        Properties properties = new Properties();

        String user = "user";
        String pwsd = "password";
        String connectStr = "jdbc:snowflake://My_Environment.snowflakecomputing.com";

        Connection conn = DriverManager.getConnection(connectStr, user, pwsd);
        return conn;
      }

 }

Build path:

Build path

And the related stacktrace:

Driver not found
java.sql.SQLException: No suitable driver found for jdbc:snowflake://My_Environment.snowflakecomputing.com
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.GriefUI.DBComponents.Snowflake_Driver.getConnection(Snowflake_Driver.java:54)
at com.GriefUI.DBComponents.Snowflake_Driver.databaseConnection(Snowflake_Driver.java:20)
at com.GriefUI.Servers.PushServer.doPost(PushServer.java:60)
at com.GriefUI.Servers.PushServer.doGet(PushServer.java:47)

Upvotes: 2

Views: 12733

Answers (2)

Nestor Milyaev
Nestor Milyaev

Reputation: 6605

I believe the error message may be misleading.

In my case, Snowflake server is behind a firewall/proxy and I get the same error when connection cannot be obtained physically. It all works on the server all right - I get the error when trying to connect to the DB from my local machine that is on the opposite side of the firewall.

So, make sure your application can physically connect to the DB or use a proxy parameter in your java launcher, such as

-Dhttp.proxyHost=a-proxy.host.domain.net -Dhttp.proxyPort=8080 or similar

Upvotes: 0

Rachel McGuigan
Rachel McGuigan

Reputation: 541

The research I would suggest taking a look at is: https://docs.snowflake.net/manuals/user-guide/jdbc-configure.html

This answer also looked helpful: https://stackoverflow.com/a/54504514/12127815 "adding the jar to classpath, and then running the following command, Class.forName("provided driver name") in the calling class? " Though a light jar has been asked to be an an enhancement here: "[open]Light driver jar? #174" https://github.com/snowflakedb/snowflake-jdbc/issues/174

Integrating the driver to a project: https://docs.snowflake.net/manuals/user-guide/jdbc-download.html#integrating-the-driver-into-a-project Specific information copied from the documentation: "To integrate the driver into a project, add the necessary tags to your pom.xml file. For example:

<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>3.9.2</version>

Where the tag specifies the version of the driver you wish to integrate. Note that version 3.9.2 is used in this example for illustration purposes only. The latest available version of the driver may be higher."

Others may have better insights.

Upvotes: 1

Related Questions