blob.getBytes(1,(int)(blob.length()));这个语句产生异常,提示java.lang.ArrayIndexOutOfBoundsException 。
但我感觉这个语句没错啊,不知是什么原因?请大家帮忙!

解决方案 »

  1.   

    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
    通过这个,好像是没问题啊
      

  2.   

    你数组没初始把,或者你的blob有问题
      

  3.   

    blob=rs.getBlob("message_body");
    int size=(int)(blob.length());
    if(size>0){
         byte[] bytes=null;
         bytes=blob.getBytes(1,size);
    }
    size也取到值了,为712
      

  4.   

    int size=(int)(blob.length());??????????直接int size=(blob.length());不就行了吗??
    还有就是把blob.getBytes(1,(int)(blob.length()));换成blob.getBytes(1,(blob.length()));然后你再试试
      

  5.   

    OnlyFor_love(【光在哪里,荣耀就在哪里】) ,blob.length()是long型的,所以要转换的
      

  6.   

    blob.getBytes(1,(int)(blob.length()));
    是不要第0号byte吗?那么从1位取到blob.length()长的位数肯定数组越界啊!
      

  7.   

    blob=rs.getBlob("message_body");
    int size=(int)(blob.length());
    if(size>0){
         byte[] bytes=null;
         bytes=blob.getBytes(1,size-8);
    }
    感觉一个字符,是8字节,试试这个
      

  8.   

    错了,应该是9的。bytes=blob.getBytes(1,size-9);