title: Spring jdbc 'select for update'
body: <p>I have the following method that I use with Spring JDBC</p>
  
  <pre><code>public String getState() {
      String stateLink = template.queryForObject(
              "select state_url from state_scrape_queue where in_use = false ORDER BY scrape_timestamp NULLS FIRST LIMIT 1",
              (result, rowNum) -&gt; {
                  return result.getString("state_url");
              });
      return stateLink;
  }
  </code></pre>
  
  <p>I can't find an example of how to do a <a href="https://www.postgresql.org/docs/9.0/sql-select.html#SQL-FOR-UPDATE-SHARE" rel="nofollow noreferrer">for update</a> with Spring JDBC. I want <code>in_use</code> to be set to true using for update. </p>
  
  <p>I need to use select for update since this application will be used in a multi-threaded fashion. I don't want more than one thread to get the same row and the way to prevent that is by using <code>select for update</code></p>
  
  <p>I was able to do this with plain JDBC, here is the question I asked how to do it with plain JDBC</p>
  
  <p><a href="https://stackoverflow.com/questions/46995155/select-for-update-with-jdbc">select &quot;for update&quot; with JDBC?</a></p>
  
  <p>Anyone know how this would be done?</p>