title: Postgresql, JDBC, and streaming BLOBs
body: <p>I am trying to retrieve a blob from a postgres database using the jdbc drivers.  It is too big to have in memory so I want to stream it as a download.  I tried using the getBinaryStream method on ResultSet, but it turns out that this method actually reads it all into memory, so doesn't work for large file.</p>
  
  <p>Apparently, one can use the getBlob method on the resultset and the presumeably get the inputstream from the blob and go from there, but that is where I run into my problem.  </p>
  
  <pre><code>PreparedStatement ps = con.prepareStatement("select data from file_data WHERE ID = ?");
  ps.setLong(1,file.fileData.id)
  ResultSet rs = ps.executeQuery()
  if(rs.next()){
          rs.getBlob("data")
  </code></pre>
  
  <p>That is the code I'm running.  When it gets to that last line it throw out an error that I cannot make sense of...</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException: Bad value for type long : xxxxxx</p>
  </blockquote>
  
  <p>"xxxxxx" then is the contents of the file.  You can imagine that gets quite long, but not really the point.  </p>
  
  <p>I'm stuck here.  Does anyone have any ideas on what is going on?  Heck I'll even take alternative methods for streaming large blobs as a download.</p>