Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop or terminate long running query in JDBC

Tags:

java

oracle

jdbc

Is there any way to stop or terminate long running Oracle query in JDBC ? It often end up with restart application server to get jdbc to disconnect from Oracle DB.

Looking for functionality similar to SQL Plus - Kill session in Java or JDBC

in SQL Plus

SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';

any clue to perform in java ?

like image 673
AzizSM Avatar asked Jun 08 '12 10:06

AzizSM


2 Answers

short of the jdbc timeout, if you run your query in another thread, you can use Statement.cancel() to kill it.

like image 143
Matt Avatar answered Oct 24 '22 14:10

Matt


Possibly bit off, but I would propose using JDBC Timeout instead. It has the added benefit of actually terminating gracefully instead of by force.

With modern app servers you can usually define JDBC timeout from datasource configuration.

like image 26
eis Avatar answered Oct 24 '22 15:10

eis