To support the retrieval of query IDs from the Athena server, the connector provides an interface called com.interfaces.core.IStatementQueryInfoProvider. This interface provides the following functions:
  • public String getPreparedQueryId();
    This function gets the ID of the query used when the statement was prepared. It returns the prepared query ID if available, or a null value if the ID is unavailable.
  • public String getQueryId();
    This function gets the ID of the executed query. It returns the query ID if available, or a null value if the ID is unavailable.
The statement class used by the connector implements this interface, so these functions can be accessed if you unwrap the Java Statement object to this interface. The following example shows how a Statement object might be used:
// Import the IStatementQueryInfoProvider interface
// Create the connection as normal
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM sen.integer_table");
String queryId = stmt.unwrap(IStatementQueryInfoProvider.class).getQueryId(); // Get query id after a statement has been executed.
The following example shows how a PreparedStatement object might be used:
// Import the IStatementQueryInfoProvider interface
// Create the connection as normal
PreparedStatement prepStmt = conn.prepareStatement("SELECT * FROM sen.integer_table");
String prepQueryId = prepStmt.unwrap(IStatementQueryInfoProvider.class).getPreparedQueryId();
prepStmt.execute();
String queryId = prepStmt.unwrap(IStatementQueryInfoProvider.class).getQueryId();