贴个Statement.cancel()的文档:
/**
Cancels this Statement
object if both the DBMS and
driver support aborting an SQL statement.
This method can be used by one thread to cancel a statement that
is being executed by another thread.
@exception SQLException if a database access error occurs or
this method is called on a closed Statement
@exception SQLFeatureNotSupportedException if the JDBC driver does not support
this method
*/
void cancel() throws SQLException;
根据javadoc的描述,如果DBMS和驱动都支持的话是可以使用这个api结束
可以先设置超时时间:
void setQueryTimeout(int seconds) throws SQLException;
捕获这个异常然后cancel()