我希望使用JDBC连接并将数据插入到我的Amazon Redshift表中。 我编写了以下代码,但在Class.forName行处一直出现错误。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class RedShiftDataEmitter {
static final String redshiftUrl = "jdbc:redshift://xxxxxxxxx:5439/xxxxxx";
static final String masterUsername = "xxxxxxx";
static final String password = "xxxxxxx";
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
Class.forName("com.amazon.redshift.jdbc41.Driver");
Properties properties = new Properties();
properties.setProperty("user", masterUsername);
properties.setProperty("password", password);
connection = DriverManager.getConnection(redshiftUrl, properties);
// Further code to follow
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}
提醒一下,我可以使用SQL Workbench连接到同一集群。我的pom.xml如下:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-redshift -->
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc41</artifactId>
<version>1.2.1.1001</version>
</dependency>