1
votes

We are trying to load JSON files using Java from a file location to Snowflake Named Stage. Currently, the PUT command only works for ODBC and not JDBC. So is there any way to execute PUT command using Java code?

Thanks

1

1 Answers

2
votes

The Snowflake JDBC Driver does support use of PUT statements for local file uploads. The following java statement is considered a valid query and the file is uploaded:

statement.executeQuery("PUT file:///tmp/foo.json @JSONSTAGE/ overwrite=true");

Running it under a logger produces logs such as the following (logs here are from JDBC driver version v3.12.2):

n.s.c.jdbc.SnowflakeFileTransferAgent$1 FINE call:778 - filePath: /tmp/foo.json
n.s.c.jdbc.SnowflakeFileTransferAgent FINE uploadFiles:1751 - Done with uploading

The JDBC driver also supports a more efficient way of uploading a stream directly, documented here.