Easiest way to convert a Blob into a byte array Easiest way to convert a Blob into a byte array arrays arrays

Easiest way to convert a Blob into a byte array


the mySql blob class has the following function :

blob.getBytes

use it like this:

//(assuming you have a ResultSet named RS)Blob blob = rs.getBlob("SomeDatabaseField");int blobLength = (int) blob.length();  byte[] blobAsBytes = blob.getBytes(1, blobLength);//release the blob and free up memory. (since JDBC 4.0)blob.free();


The easiest way is this.

byte[] bytes = resultSet.getBytes("my_field");