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无法进入循环!无法输出
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无法进入循环!无法输出
解决方案 »
- 匿名内部类是否可以实现接口???
- RCP工程中如何动态的控制工具栏的隐藏和显示
- 简单问题,java文件读入的时候,如何动态分配缓存大小?100分
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 有一个可以直接NEW 来代替他的方法是什么???
- sql语句
- jdk最新版本号
- PHP的crypt()生成的密文,我用java怎么验证?
- JTable如何排序??急切!!
- 我的程序不能运行,我查过资料,似乎是CLASSPATH的问题,但是.....
- 较简单,但搞不定的一个问题:关于滚动条。几行代码,烦请相助!
- 急求Window 2K 上 IIS 5 + Tomcat-4.1.27 + JK-2.0.4 的整合技术
- 一个垃圾回收的问题
response.getOutputStream().write(b,0,len);
response.getOutputStream().write(b,0,b.length);
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. 是我看错了,对不起
> in = rs.getBinaryStream("img");
>}这个循环一定是不合理的。