[学习笔记]二进制数据的处理(1) 普通二进制数据处理 B -------读取数据库中二进制数据

<% @page contentType = " text/html "  pageEncoding = " UTF-8 " %>
<% @page import = " cn.java.* " %>
<% @page import = " java.sql.* " %>
<% @page import = " java.text.* " %>
<% @page import = " java.io.* " %>
<% @page import = " java.util.* " %>

<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.01 Transitional//EN "
   
" http://www.w3.org/TR/html4/loose.dtd " >

< html >
    
< head >
        
< meta http - equiv = " Content-Type "  content = " text/html; charset=UTF-8 " >
        
< title > JSP Page </ title >
    
</ head >
    
< body >
  
<%

  
             
                Connection conn 
=   null ;
               Statement stmt
= null ;
                ResultSet rs
= null ;
            
try   {
              
                String sql 
= "select binfile from bindata where id=5";
                conn 
= DBUtil.getConnection();
               stmt
=conn.createStatement();
         
                rs
=stmt.executeQuery(sql);
             
while(rs.next()){
                 ServletOutputStream sout
=response.getOutputStream();
                 InputStream 
in=rs.getBinaryStream(1);
                 
byte b[] = new byte[0x7a120];//获得二进制输入流
                 while(in.read(b)!=-1)
                 sout.write(b);
//输出字符流
                 }

                 
                 sout.flush();
                 sout.close();
//关闭sout输出流
             }

       
        
             
            }
   catch  (SQLException ex)  {
                out.println(ex.getMessage());
            }


            
finally   {
                
try {
                 
                    DBUtil.close(rs, stmt, conn);
                }
 catch (Exception ex) {
               out.println(ex.getMessage());
                }

            }

%>
    
</ body >
</ html >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值