如何调用java.sql.Connection :: abort?

时间:2018-08-08 17:17:28

标签: java jdbc prepared-statement swingworker

我想写一个SwingWorker,当用户取消任务时,它是:1)取消PreparedStatement,2)中止Connection

下面是一些代码来说明:

class Task extends SwingWorker<Void, Void> {

    Connection conn;
    PreparedStatement p_stmt;
    @Override
    protected Void doInBackground() throws Exception {
        ResultSet results = p_stmt.executeQuery();
        while(results.next()) {
            if(isCancelled())
                return;
        }
        return null;
    }

    void cancell() {
        cancel(true);
        try {
            p_stmt.cancel();
            conn.abort(/* How do I properly implement Executor? */);
        } catch (SQLException e) {
            handleError(e);
        }
    }

    @Override
    protected void done() {
        try {
            get();
        } catch (ExecutionException | InterruptedException e) {
            handleError(e);
        }
    }
}

static void handleError(Exception e) {
    // ...
}

此行:

conn.abort(/* How do I properly implement Executor? */);

这是我感兴趣的那一行。我应该传递给Connection::abort吗?

0 个答案:

没有答案