logo       

SQL Resources: msg#00026

java.findbugs.general

Subject: SQL Resources

This is a multi-part message in MIME format.

Hi All,

 

I have Database code that find bugs is reporting as a potential problem, though I can’t see anything wrong with it. The code follows this pattern

 

 

  public void dropTestTable() {

    Statement stmt = null;

    try{

      stmt = con.createStatement();

      stmt.executeUpdate( "DROP TABLE TEST" );

    }catch( SQLException e ) {

      e.printStackTrace();

    }finally{

      SQLUtils.closeResources( stmt );

    }

  }

 

The SQLUtils.closeResources method is

 

  public static void closeResources( Statement ... stmts ){

    for( Statement stmt : stmts ){

      try {

        if( stmt != null )

          stmt.close();

      } catch (SQLException e) {

        e.printStackTrace();

      }

    }

  }

 

Findbugs is telling me that the method may fail to close the database resource. Is there something obvious that I’m missing?

 

Thanks

Mark Hillary



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise