title: Reading MEDIUMBLOB from MySQL in java
body: <p>This is for the first time I am working with the Blob data types. 
  I am storing the image files in MEDIUMBLOB datatype in MySQL database. Now, I want to retrieve it using a JAVA application. 
  So far, I found tutorials making use of <code>com.mysql.jdbc.Blob</code>.
   I tried, </p>
  
  <pre><code>Blob imgAsBlob = resultset.getBlob("image");
  byte[] imgAsBytes = imgAsBlob.getBytes(1, (int) imgAsBlob.length());
  </code></pre>
  
  <p>but I get an error at <code>imgAsBlob.getBytes(1, (int) imgAsBlob.length())</code> because the second argument is larger (46352) than the BLOB's length: </p>
  
  <pre><code>java.sql.SQLException: "pos" + "length" arguments cannot be larger than the BLOB's length.
  </code></pre>
  
  <p>Is there any other way than getBlob() method or any other class than <code>com.mysql.jdbc.Blob</code> which I can use?</p>
  
  <p>Thanks.</p>