PreparedStatement  sql=con.prepareStatement(sqls);
rs  =  sql.executeQuery();
while(rs.next()){
in  =  rs.getBinaryStream("img");
}
response.reset();
response.setContentType("application/x-msdownload");
byte[] b = new byte[1024]; 
int  len;
if(in!=null){
   while((len=in.read(b))>0)
      response.getOutputStream().write(b,0,len);
      in.close();
}else{out.println("没有图片");}
数据库(oracle)字段类型是 <Long Raw> 存储的是图片,取数据时没问题,就是在读取数据的时候 in.read(b)的时候总是==-1无法进入循环!无法输出

解决方案 »

  1.   

    会不会还没read,rs就被你close 了?
      

  2.   

    不可能啊!! in 已经将 rs 记录集的直得出来了啊!
      

  3.   

    while((len=in.read(b))>0)  //这里有错误,你看看InputStream的API
          response.getOutputStream().write(b,0,len);
      

  4.   

    可以改成while((in.read(b))>0)  //这里有错误,你看看InputStream的API
          response.getOutputStream().write(b,0,b.length);
      

  5.   

    Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown. 
    If b is null, a NullPointerException is thrown. If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b. The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected. 是我看错了,对不起
      

  6.   

    >while(rs.next()){
    >  in  =  rs.getBinaryStream("img");
    >}这个循环一定是不合理的。