0

I'm currently trying to make a simple connection to our Snowflake database. I followed the documentation on their site: https://docs.snowflake.net/manuals/user-guide/jdbc-configure.html and verified that the connection string is correct.

Everytime I launch the program, however, I get an SQLException stating it can't find a jar, or that there is no driver found:

[19:28:54] [Server thread/WARN]: driver not found
[19:28:54] [Server thread/WARN]: java.sql.SQLException: No suitable driver found for jdbc:snowflake://d9022.east-us-2.azure.snowflakecomputing.com/
[19:28:54] [Server thread/WARN]:        at java.sql.DriverManager.getConnection(Unknown Source)
[19:28:54] [Server thread/WARN]:        at java.sql.DriverManager.getConnection(Unknown Source)
[19:28:54] [Server thread/WARN]:        at com.mcnations.nationsatwar.jdbc.DatabaseManager.getConnection(DatabaseManager.java:44)
[19:28:54] [Server thread/WARN]:        at com.mcnations.nationsatwar.jdbc.DatabaseManager.init(DatabaseManager.java:50)
[19:28:54] [Server thread/WARN]:        at com.mcnations.nationsatwar.jdbc.DatabaseManager.<init>(DatabaseManager.java:19)
[19:28:54] [Server thread/WARN]:        at net.mcnations.nationsatwar.Player.NationPlayer.<init>(NationPlayer.java:54)
[19:28:54] [Server thread/WARN]:        at net.mcnations.nationsatwar.NationsInitializer.playerLogin(NationsInitializer.java:78)

I use Maven for my dependencies. In my POM, I simply have:

<!-- https://mvnrepository.com/artifact/net.snowflake/snowflake-jdbc -->
        <dependency>
            <groupId>net.snowflake</groupId>
            <artifactId>snowflake-jdbc</artifactId>
            <version>3.9.2</version>
        </dependency>

Even with the Maven dependency stated (in accordance with Snowflake's documentation) I still got the no driver exception. I then added the jar into my build path as well hoping that (maybe) you needed both a maven dependency and an actual .jar file on your build path. This did not fix the problem.

At this point I'm at a loss. I do not know what I am doing wrong, nor do I know how to address it.

My connection class:

package com.mcnations.nationsatwar.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import net.mcnations.nationsatwar.Player.NationPlayer;

public class DatabaseManager {

    private NationPlayer player;

    public DatabaseManager(NationPlayer player) throws SQLException{
        this.player = player;

        init();

    }

    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();

        properties.put("user", "NationsUser");
        properties.put("password", "//myPassword");
        properties.put("db", "//myDB");
        properties.put("role", "SYSADMIN");

        String connectStr = "jdbc:snowflake://9022.east-us-2.azure.snowflakecomputing.com/";

        return DriverManager.getConnection(connectStr, properties);

    }

    private static void init() throws SQLException{

        Connection connObject = getConnection();

        Statement statement = connObject.createStatement();

        ResultSet rSet = statement.executeQuery("SELECT * FROM PlayerData");

        if(rSet == null) {
            System.out.println("rSet is null");
        }
        else {
            System.out.println(rSet.next());
        }

    }

}
Matthew
  • 817
  • 1
  • 13
  • 39
  • I checked the maven repository of Snowflake client, and it works fine. Do you get this error when you launch the application through your Java IDE or do you get this error after you deploy your application? – Gokhan Atil Dec 30 '19 at 09:05
  • I get this error only when I deploy the application – Matthew Dec 30 '19 at 16:28
  • In this case, maven download the JAR as expected, but you are not deploying all required JARS. At least snowflake driver JAR is missing. Check my detailed answer. – Gokhan Atil Dec 31 '19 at 08:27

4 Answers4

1

As I understand, you do not deploy the required JAR (snowflake-jdbc-3.9.2.jar) with your application, so it can not find the driver in classpath. Here's similar output when I try to run my application without correct classpath:

java -cp snowflaketest01-1.0-SNAPSHOT.jar com.gokhanatil.snowflaketest01.Main
driver not found
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:snowflake://xxxxxxxxxx.snowflakecomputing.com/
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
    at com.gokhanatil.snowflaketest01.Main.getConnection(Main.java:28)
    at com.gokhanatil.snowflaketest01.Main.main(Main.java:36)

You may include the JAR by yourself, or you can let Maven pack required the JARs to your final jar. You may include the following to your pom file:

...
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>
...

So it produces one big JAR file which includes all required JAR (snowflake driver etc):

java -cp snowflaketest01-1.0-SNAPSHOT-jar-with-dependencies.jar com.gokhanatil.snowflaketest01.Main

Please check java classpath: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html

and including the dependencies in a JAR with Maven: Including dependencies in a jar with Maven

Gokhan Atil
  • 9,278
  • 2
  • 11
  • 24
0

The error "java.sql.SQLException: No suitable driver found for java.sql.SQLException: No suitable driver found for jdbc:snowflake://.snowflakecommputing.com" occurs when you try to connect Snowflake database using Java program but either you don't have Snowflake JDBC driver {ex . snowflake-jdbc-3.11.0.jar} in your classpath or driver is not registered before calling the getConnection() method.

Could you please make sure you have included the Snowflake JDBC Driver "snowflake-jdbc-3.11.0.jar" into your Build library path.

0

This error is caused by the application not being able to find the Snowflake jdbc driver. This can happen when jar files have required parameters (ie. config.yml).

Because the Snowflake JDBC driver does not have these required files, I told the main class to launch both itself, and the Snowflake JDBC jar file together via:

@echo off
title Server Console
java -classpath "spigot-1.15.1.jar;lib/*" org.bukkit.craftbukkit.Main
PAUSE

Where the line java -classpath "spigot-1.15.1.jar;lib/*" org.bukkit.craftbukkit.Main states

  1. Start a java application
  2. Down the classpath of "my_main_jar.jar;"
  3. launch with all files in the /lib directory
  4. and point to the main class (in my case, org.bukkit.craftbukkit.Main)

These are command-line arguments that are essentially "handed off" to the application.

Matthew
  • 817
  • 1
  • 13
  • 39
-1
I am using Eclipse and i never faced any such issue .
Create a Maven Project , put dependencies and you are good .

File->New->Project->Maven Project .Give a name to the project ->Finish .

Now add the below dependency.

    <dependency>
            <groupId>net.snowflake</groupId>
            <artifactId>snowflake-jdbc</artifactId>
            <version>3.9.0</version>
        </dependency>

Can you check in your ~/.m2 folder if you are getting the jar or not ?

Ankur Srivastava
  • 855
  • 9
  • 10
  • This answer did not attempt to offer any solutions at all - you simply stated what I said I had already tried. It SHOULD work in the way you said, but it doesn't. That is why I am asking for help. – Matthew Dec 30 '19 at 23:56
  • Its not related to Snowflake jars anyways .Its the way you are building and deploying. – Ankur Srivastava Dec 31 '19 at 04:16