Cancel a Statement

NuoDB does not support Statement#cancel() call which is used to stop the execution of a running SQL statement. Instead, it supplies killStatement() in the implementation class RemStatement.

To use RemStatement#killStatement(), cast a Statement object to RemStatement and supply the connection URL and connection properties, including credentials. This will cause a second connection to be created and a KILL STATEMENT command to be executed.

The internal class RemStatement is potentially subject to change. Care should be taken when upgrading the JDBC driver to ensure that any code using RemStatement still compiles.
Statement.isWrapperFor() returns false in all cases and should not be used.

Example

/* Assume pStatement is a PreparedStatement object that needs to be killed... */

final String dburl = "jdbc:com.nuodb://host:48004/my_database";

final Properties properties = new Properties()
    {
        {
            put("user", getDBUser());
            put("password", getDBPassword());
            put("schema", getDBSchema());
         }
    };

RemStatement remStmt = null;

if (statement instanceof RemStatement)
    /* Simple cast to subtype */
    remStmt = ((RemStatement)pStatement);
else {
    try {
        /* statement may be a proxy wrapping an actual Statement instance */
        remStmt= statement.unwrap(RemStatement.class);
    }
    catch (ClassCastException e)
        logger.warn("Unable to kill statement, request ignored.");
}

if (remStmt != null)
    remStmt.killStatement(dburl, properties);