title: How to obtain a lock in DB2 with select for update without transferring data?
body: <p>Through a ton of experiments I found that</p>
  
  <p><em>(<a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html" rel="nofollow noreferrer"><code>jdbcTemplate</code> is a <code>JdbcTemplate</code></a> and is just used to make execution of queries easy. It has no real relation to the question)</em></p>
  
  <pre><code>jdbcTemplate.query(
      "select 0 from example where id = 23 for update with rs use and keep update locks", 
      rs -&gt; {
          rs.next();
          return null;
  });
  </code></pre>
  
  <p>obtains a lock on the selected row, while this one doesn't:</p>
  
  <pre><code>jdbcTemplate.query(
      "select 0 from example where id = 23 for update with rs use and keep update locks", 
      rs -&gt; {
          return null;
  });
  </code></pre>
  
  <p>I assume for the same reason the following does not obtain a lock:</p>
  
  <pre><code>jdbcTemplate.execute(
      "select id from example where id = 23 for update with rs use and keep update locks"
  );
  </code></pre>
  
  <p>I have a two part question:</p>
  
  <ol>
  <li>What the heck is going on?</li>
  <li>How can I execute the select for update in the database so it does result in the lock, but does not return data per selected row? Maybe some kind of script?</li>
  </ol>
  
  <p><a href="https://github.com/schauder/db2-locks" rel="nofollow noreferrer">There is a Github repository testing these (and many more variants)</a>. </p>