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