public byte[] getBytes(long pos, int length) throws SQLException Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes. This byte array contains up to length consecutive bytes starting at position pos. Parameters: pos - the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1 length - the number of consecutive bytes to be copied Returns: a byte array containing up to length consecutive bytes from the BLOB value designated by this Blob object, starting with the byte at position pos Throws: SQLException - if there is an error accessing the BLOB value 通过这个,好像是没问题啊
你数组没初始把,或者你的blob有问题
blob=rs.getBlob("message_body"); int size=(int)(blob.length()); if(size>0){ byte[] bytes=null; bytes=blob.getBytes(1,size); } size也取到值了,为712
int size=(int)(blob.length());??????????直接int size=(blob.length());不就行了吗?? 还有就是把blob.getBytes(1,(int)(blob.length()));换成blob.getBytes(1,(blob.length()));然后你再试试
int length)
throws SQLException
Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes. This byte array contains up to length consecutive bytes starting at position pos. Parameters:
pos - the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1
length - the number of consecutive bytes to be copied
Returns:
a byte array containing up to length consecutive bytes from the BLOB value designated by this Blob object, starting with the byte at position pos
Throws:
SQLException - if there is an error accessing the BLOB value
通过这个,好像是没问题啊
int size=(int)(blob.length());
if(size>0){
byte[] bytes=null;
bytes=blob.getBytes(1,size);
}
size也取到值了,为712
还有就是把blob.getBytes(1,(int)(blob.length()));换成blob.getBytes(1,(blob.length()));然后你再试试
是不要第0号byte吗?那么从1位取到blob.length()长的位数肯定数组越界啊!
int size=(int)(blob.length());
if(size>0){
byte[] bytes=null;
bytes=blob.getBytes(1,size-8);
}
感觉一个字符,是8字节,试试这个