我目前正在尝试与我们的Snowflake数据库建立简单连接。我遵循了他们网站上的文档:https://docs.snowflake.net/manuals/user-guide/jdbc-configure.html并验证连接字符串正确。
但是,每次启动该程序时,我都会收到一个SQLException,指出它找不到jar,或者找不到驱动程序:
[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)
我将Maven用于依赖项。在我的POM中,我仅具有:
<!-- https://mvnrepository.com/artifact/net.snowflake/snowflake-jdbc -->
<dependency>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>3.9.2</version>
</dependency>
即使陈述了Maven依赖关系(根据Snowflake的文档),我仍然遇到no driver exception。然后,我将jar添加到构建路径中,并希望(也许)在构建路径上既需要maven依赖关系,又需要实际的.jar文件。这不能解决问题。
此时,我很茫然。我不知道自己在做什么错,也不知道如何解决。
我的连接类别:
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());
}
}
}
当您尝试使用Java程序连接Snowflake数据库时,发生错误“ java.sql.SQLException:没有为java.sql.SQLException找到合适的驱动程序:jdbc:snowflake://.snowflakecommputing.com没有找到合适的驱动程序,但是要么您没有Snowflake JDBC驱动程序{ex。在调用getConnection()方法之前,未在您的类路径或驱动程序中注册雪花-jdbc-3.11.0.jar。
您能否确保已将Snowflake JDBC驱动程序“ snowflake-jdbc-3.11.0.jar”包含在Build库路径中。