Yanjing Wang
Yanjing Wang

Reputation: 46

mysql query with state showing "Sending data" or "Writing to net" can't be cancelled through statement.cancel() method

I make a mysql query joining two large tables without on condition filter, such as select * from a,b.

I hit show processlist command and show the sql state is being Sending data, then I invoke my code statement.cancel().

I would think the query has been killed, but the query is still in Sending data state. I notice that mysql implementation executes the following code

if (!this.statementExecuting.get()) {
     return;
}

Could someone have any other way to cancel such queries?

Upvotes: 0

Views: 584

Answers (1)

Jochen Reinhardt
Jochen Reinhardt

Reputation: 843

Have you tried interrupting the thread that waits for the query execution to finish?

I assume you are running multiple threads as you are able to call statement.cancel() while the statement is being executed. So you should be able to get a reference to this thread and call thread.interrupt() on it.

Not sure how the JDBC driver will handle the InterruptedException - maybe you will have to take care about it in your code.

Upvotes: 0

Related Questions