 <p>You never place any content in your <code>StringBuffer</code> <code>buffer</code>, so it is empty when you write it to file:</p> <pre><code>bw.write(buffer.toString()); </code></pre> <p><code>buffer</code> could potentially consume a large amount of memory here.</p> <p>A better approach to writing the data to file would be to write the data as you read it from the database:</p> <pre><code>while (rs.next()) { sampleIddisp = rs.getString(1); ... bw.write(....); } </code></pre>