84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
由于查询的sql过于复杂,导致前端请求action超时,页面已经停止了,但此时从数据库show processlist看,那条查询语句还在继续执行,请问下,怎么在前端超时的同时,那条查询sql也能自动被kill掉呢?不然数据库服务器的cpu一直被占着。。
业精于勤,荒于嬉;行成于思,毁于随。
贴个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()
mysql超时设置吧
贴个Statement.cancel()的文档:
根据javadoc的描述,如果DBMS和驱动都支持的话是可以使用这个api结束
可以先设置超时时间:
捕获这个异常然后cancel()
mysql超时设置吧