Blob类型转换成byte数组类型存储到Oracle数据库
import java.io.BufferedInputStream;
import java.io.IOException;
import java.sql.Blob;
public class BlobToBytes {
/**
* 把Blob类型转换为byte数组类型
*
* @param blob
* @return
*/
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 {
is.close();
is = null;
} catch (IOException e) {
return null;
}
}
}
}