title: Sonar: "Close this PreparedStatement"
body: <p>Why is <a href="http://docs.sonarqube.org/" rel="nofollow">SonarQube</a> plugin for Jenkins complaining about the open statement if I close it in the finally block?</p>
  
  <p>(I need to validate database connections in a separate function.)</p>
  
  <pre><code>final String PING = "SELECT 1 from dual";
  
  public boolean validateConnection(Connection conn) { 
  
      PreparedStatement statement = null;
      try{
          if(conn == null){
              LOGGER.log( LogEntries.PingError, "Null connection on PING. Reached max # of connections or network issue. Stats: "+getCacheStatistics() );
              return false;
          }
  
          if(conn.isClosed()){
              // logger
              return false;   
          } 
  
          statement = conn.prepareStatement( PING ); //%%%%%% SONAR: Close this "PreparedStatement".
          statement.setQueryTimeout(QUERY_TIMEOUT);
  
          try( ResultSet rs = statement.executeQuery() ){
              if ( rs != null &amp;&amp; rs.next() ) {
                  return true;
              }
          }catch(Exception exRs){
              // logger
              throw exRs;
          }
      }catch(Exception ex){
          // logger
      }finally{
          try{
              statement.close();
          }catch(Exception excpt){
              // logger
          }
      }
      return false;
  }
  </code></pre>