I would like to write a SwingWorker
that, when the user cancels the task, it: 1) cancels the PreparedStatement
and 2) aborts the Connection
.
Here is some code to illustrate:
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) {
// ...
}
This line:
conn.abort(/* How do I properly implement Executor? */);
Is the line I'm interested in. What should I pass to Connection::abort
?