我目前正在开发一个应用程序。我们正在从文件系统转移到 Snowflake 数据库。我似乎无法连接到数据库 - 我不断遇到“找不到合适的驱动程序”错误。
正确的驱动程序已加载并安装到构建路径中。有谁知道发生了什么事吗?
代码:
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;
}
}
构建路径:
婷婷同学_
守候你守候我
相关分类