Java handler examples for stored procedures¶
Using Snowpark APIs for asynchronous processing¶
In the following example, the getResultJDBC
procedure executes an asynchronous child job that waits 10 seconds.
CREATE OR REPLACE PROCEDURE getResultJDBC()
RETURNS VARCHAR
LANGUAGE JAVA
RUNTIME_VERSION = 2.12
PACKAGES = ('com.snowflake:snowpark:latest')
HANDLER = 'TestScalaSP.asyncBasic'
AS
$$
import java.sql.*;
import net.snowflake.client.jdbc.*;
class TestScalaSP {
public String asyncBasic(com.snowflake.snowpark.Session session) throws Exception {
Connection connection = session.jdbcConnection();
SnowflakeStatement stmt = (SnowflakeStatement)connection.createStatement();
ResultSet resultSet = stmt.executeAsyncQuery("CALL SYSTEM$WAIT(10)");
resultSet.next();
return resultSet.getString(1);
}
}
$$;