找不到合适的驱动程序找到雪花 JDBC

No suitable driver found snowflake JDBC

我目前正在处理一个应用程序。我们正在从我们的文件系统转移到我们的 Snowflake 数据库。我似乎无法连接到数据库 - 我不断遇到 "no suitable driver found" 错误。

正确的驱动程序已加载并安装到构建路径中。 有人知道怎么回事吗?

代码:

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

 }

构建路径:

以及相关的堆栈跟踪:

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)

我建议看一看的研究是:https://docs.snowflake.net/manuals/user-guide/jdbc-configure.html

这个答案看起来也很有帮助: "adding the jar to classpath, and then running the following command, Class.forName("provided driver name") in the calling class?" 尽管这里要求光罐作为增强功能:“[open]Light driver jar?#174”https://github.com/snowflakedb/snowflake-jdbc/issues/174

将驱动程序集成到项目中:https://docs.snowflake.net/manuals/user-guide/jdbc-download.html#integrating-the-driver-into-a-project 从文档中复制的特定信息:“要将驱动程序集成到项目中,请将必要的标记添加到您的 pom.xml 文件中。例如:

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

标签指定您希望集成的驱动程序版本。请注意,此示例中使用的版本 3.9.2 仅用于说明目的。最新可用的驱动程序版本可能更高。"

其他人可能有更好的见解。