一个奇怪的异常!!!!

rcrain 2005-11-04 10:39:30
blob.getBytes(1,(int)(blob.length()));这个语句产生异常,提示java.lang.ArrayIndexOutOfBoundsException 。
但我感觉这个语句没错啊,不知是什么原因?请大家帮忙!
...全文
168 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
rcrain 2005-11-05
  • 打赏
  • 举报
回复
升级驱动到最新的,就ok了。谢谢大家的帮忙
OnlyFor_love 2005-11-04
  • 打赏
  • 举报
回复
int size=(int)(blob.length());??????????



直接int size=(blob.length());不就行了吗??


还有就是把blob.getBytes(1,(int)(blob.length()));换成blob.getBytes(1,(blob.length()));

然后你再试试
rcrain 2005-11-04
  • 打赏
  • 举报
回复
blob=rs.getBlob("message_body");
int size=(int)(blob.length());
if(size>0){
byte[] bytes=null;
bytes=blob.getBytes(1,size);
}
size也取到值了,为712
xuender 2005-11-04
  • 打赏
  • 举报
回复
这句没有问题,要看你之前怎么样了
Mark_MaoHUA 2005-11-04
  • 打赏
  • 举报
回复
你数组没初始把,或者你的blob有问题
chinatelly 2005-11-04
  • 打赏
  • 举报
回复
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
通过这个,好像是没问题啊
chinatelly 2005-11-04
  • 打赏
  • 举报
回复
jdk坏了吧??
chinatelly 2005-11-04
  • 打赏
  • 举报
回复
错了,应该是9的。bytes=blob.getBytes(1,size-9);
chinatelly 2005-11-04
  • 打赏
  • 举报
回复
blob=rs.getBlob("message_body");
int size=(int)(blob.length());
if(size>0){
byte[] bytes=null;
bytes=blob.getBytes(1,size-8);
}
感觉一个字符,是8字节,试试这个
liu_you 2005-11-04
  • 打赏
  • 举报
回复
blob.getBytes(1,(int)(blob.length()));
是不要第0号byte吗?那么从1位取到blob.length()长的位数肯定数组越界啊!
chinatelly 2005-11-04
  • 打赏
  • 举报
回复
你把数字初始化为一个比712大的数试试
rcrain 2005-11-04
  • 打赏
  • 举报
回复
OnlyFor_love(【光在哪里,荣耀就在哪里】) ,blob.length()是long型的,所以要转换的

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧