2 回答
TA贡献1853条经验 获得超18个赞
贴个Statement.cancel()的文档:
/**
Cancels this <code>Statement</code> 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 <code>Statement</code>
@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()
添加回答
举报