Here you can find the source of blobToBytes(Blob blob)
public static byte[] blobToBytes(Blob blob)
//package com.java2s; /**/*from w w w.j a v a 2 s . c om*/ * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.io.*; import java.sql.Blob; public class Main { public static byte[] blobToBytes(Blob blob) { BufferedInputStream is = null; try { is = new BufferedInputStream(blob.getBinaryStream()); byte[] bytes = new byte[(int) blob.length()]; int len = bytes.length; int offset = 0; int read = 0; while (offset < len && (read = is.read(bytes, offset, len - offset)) >= 0) { offset += read; } return bytes; } catch (Exception e) { return null; } finally { try { if (is != null) { is.close(); is = null; } } catch (IOException e) { return null; } } } }