title: Spring Batch read from database once, write to another database and write to CSV
body: <p>I'm new to Spring Batch and trying to implement a batch job where I </p>
  
  <ol>
  <li>Read from a MySQL database</li>
  <li>Write the results to a CSV file</li>
  <li>Do some processing of MySQL result set and write to another database.</li>
  </ol>
  
  <p>I've looked through <a href="https://stackoverflow.com/questions/25850944/spring-batch-read-once-and-write-twice">this question on StackOverflow</a>, but the main accepted answer was essentially to implement two steps that read twice from the database:</p>
  
  <pre><code>&lt;job id="myJob"&gt;
      &lt;step id="step1" next="step2"&gt;
          &lt;tasklet&gt;
              &lt;chunk reader="reader" writer="typeAwriter"/&gt;
          &lt;/tasklet&gt;
      &lt;/step&gt;
      &lt;step id="step2"&gt;
          &lt;tasklet&gt;
              &lt;chunk reader="reader" processor="processor" writer="typeBwriter"/&gt;
          &lt;/tasklet&gt;
      &lt;/step&gt;
  &lt;/job&gt;
  </code></pre>
  
  <p>Isn't there a more efficient way of doing this than reading twice from the MySQL database? For example, what if you query is quite large and drags system performance? </p>