java请求action超时,怎么停止mysql继续查询数据库?
迷茫
迷茫 2017-04-18 09:31:34
0
2
305

由于查询的sql过于复杂,导致前端请求action超时,页面已经停止了,但此时从数据库show processlist看,那条查询语句还在继续执行,请问下,怎么在前端超时的同时,那条查询sql也能自动被kill掉呢?不然数据库服务器的cpu一直被占着。。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (2)
小葫芦

Post the documentation for 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;

According to the javadoc description, if both the DBMS and the driver support it, you can use this API to end it
You can set the timeout first:

void setQueryTimeout(int seconds) throws SQLException;

Catch this exception and cancel()

    Peter_Zhu

    mysql timeout setting

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!