Maison  >  Questions et réponses  >  le corps du texte

java请求action超时,怎么停止mysql继续查询数据库?

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

迷茫迷茫2716 Il y a quelques jours353

répondre à tous(2)je répondrai

  • 高洛峰

    高洛峰2017-04-18 09:33:34

    Publiez la documentation pour 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;
        

    Selon la description javadoc, si le SGBD et le pilote le prennent en charge, vous pouvez utiliser cette API pour y mettre fin
    Vous pouvez d'abord définir le délai d'attente :

        void setQueryTimeout(int seconds) throws SQLException;
        

    Attrapez cette exception et annulez()

    répondre
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:33:34

    Paramètres de délai d'attente MySQL

    répondre
    0
  • Annulerrépondre