title: Correct order for closing various JDBC objects
body: <p>I have the following code sample:</p>
  
  <pre><code>try {
      conn = this.jdbcTemplate.getDataSource().getConnection();
      stm = conn.prepareCall("{? =" + query + "}");
      stm.registerOutParameter(1, OracleTypes.CURSOR);
      if (params != null) {
          for (int i = 0; i &lt; params.length; i++)
              stm.setString(i + 2, params[i]);
      }
      //getting result set from cursor
      stm.execute();
      res = (ResultSet) stm.getObject(1);
      return DatabaseLayerUtils.getResultSetData(res);
  } finally {
      //closing cursor
      if (res != null) res.close();
      if (stm != null) stm.close();
      if (conn != null) conn.close();
  }
  </code></pre>
  
  <p>Is the elements order in <code>finally</code> section important or not?</p>
  
  <p>Is the following code:</p>
  
  <pre><code> if (res != null) res.close();
   if (stm != null) stm.close();
  </code></pre>
  
  <p>equal to: </p>
  
  <pre><code> if (stm != null) stm.close();
   if (res != null) res.close();
  </code></pre>
  
  <p>or not? </p>
  
  <p>In a project being worked on by my colleague there are a lot of constructions like:</p>
  
  <pre><code> if (stm != null) stm.close();
   if (res != null) res.close();
  </code></pre>
  
  <p>I need to understand if this is the right syntax or if I need to fix as shown: </p>
  
  <pre><code> if (res != null) res.close();
   if (stm != null) stm.close();
  </code></pre>
  
  <p>Thanks.</p>