gpt4 book ai didi

amazon-web-services - 用于复制到 Redshift 的 Java sdk

转载 作者:行者123 更新时间:2023-12-04 12:09:07 26 4
gpt4 key购买 nike

是否可以通过 java jdbc 连接从 S3 到 Redshift 发出复制命令?

例子:
从's3://' CREDENTIALS 'aws_access_key_id=xxxxxxx;aws_secret_access_key=xxxxxxxxx'复制测试

最佳答案

是的,尝试代码如下

String dbURL = "jdbc:postgresql://x.y.us-east-1.redshift.amazonaws.com:5439/dev";
String MasterUsername = "userame";
String MasterUserPassword = "password";

Connection conn = null;
Statement stmt = null;
try{
//Dynamically load postgresql driver at runtime.
Class.forName("org.postgresql.Driver");


System.out.println("Connecting to database...");
Properties props = new Properties();


props.setProperty("user", MasterUsername);
props.setProperty("password", MasterUserPassword);
conn = DriverManager.getConnection(dbURL, props);
stmt = conn.createStatement();
String sql="copy test from 's3://' CREDENTIALS 'aws_access_key_id=xxxxxxx;aws_secret_access_key=xxxxxxxxx'"
int j = stmt.executeUpdate(sql);

stmt.close();
conn.close();
}catch(Exception ex){
//For convenience, handle all errors here.
ex.printStackTrace();
}

关于amazon-web-services - 用于复制到 Redshift 的 Java sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18465313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com