`
蛤蟆仙人
  • 浏览: 117751 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

may fail to clean up java.sql.Statement

 
阅读更多

Method com.hysoft.cache.mgmt.bulkload.DomLoad.getTotalNum(long, String) may fail to clean up java.sql.Statement

 

This method may fail to clean up (close, dispose of) a stream, database object, or other resource requiring an explicit cleanup operation.

In general, if a method opens a stream or other resource, the method should use a try/finally block to ensure that the stream or resource is cleaned up before the method returns.

This bug pattern is essentially the same as the OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE bug patterns, but is based on a different (and hopefully better) static analysis technique. We are interested is getting feedback about the usefulness of this bug pattern. To send feedback, either:

In particular, the false-positive suppression heuristics for this bug pattern have not been extensively tuned, so reports about false positives are helpful to us.

See Weimer and Necula, Finding and Preventing Run-Time Error Handling Mistakes, for a description of the analysis technique.

 

 

解决办法:

try{

             ....

  } catch (Exception e) {
            LOG.info(e);
            e.printStackTrace();
        } finally {
            try {
                if (resultSet != null) {
                    resultSet.close();
                }
            } catch (SQLException e) {
                LOG.info(e);
                e.printStackTrace();
            }
           
            try {
                if (ps != null) {
                    ps.close();
                }
            } catch (SQLException e) {
                LOG.info(e);
                e.printStackTrace();
            }
           
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException e) {
                LOG.info(e);
                e.printStackTrace();
            }
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics