I am trying to write a tool to load CSV files into multiple database. While trying to search online how to use COPY command with Snowflake, I couldn't find information how to do it in Java. This is how I do with PostgreSQL
public void loadData(Message message) throws Exception {
try (Connection connection = DriverManager.getConnection(message.getJdbcUrl(),
message.getUser(), message.password)) {
loadDataWithMode(loadRequest, (BaseConnection) connection);
} catch (Throwable error){
throw error;
}
}
public void loadDataWithMode(Message message, BaseConnection connection) throws Exception {
CopyManager copyManager = new CopyManager(connection);
String fields = message.getFields();
final String targetTableWithFields = message.getTableName() + "(" + fields + ")";
try (InputStream input = fileService.load(loadRequest.getFilePath())) {
try (InputStreamReader reader = new InputStreamReader(input, "UTF-8")) {
copyManager.copyIn("COPY " + targetTableWithFields + " from STDIN
}
}
}
I'm not familiar with Snowflake how to do it, any help will be appreciated.