Java显示ORACLE中BLOB字段图片

java 代码
 
  1. public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req, RenderResponse res) throws Exception {  
  2.         //存储过程的参数  
  3.         String pkValue = ParamUtil.getString(req, "pkValue");  
  4.         String tableName = ParamUtil.getString(req, "tableName");  
  5.         String pkName = ParamUtil.getString(req, "pkName");  
  6.         String imgColumnName = ParamUtil.getString(req, "imgColumnName");  
  7.         HttpServletResponse response = PortalUtil.getHttpServletResponse(res);  
  8.         //调用存储过程返回记录集  
  9.         ResultSet rs = ProductUtil.getImgByPK(Integer.parseInt(pkValue), tableName, pkName, imgColumnName);  
  10.         rs.next();  
  11.         //获得图片信息,强制转换为java.sql.Blob类型  
  12.         Blob blob=(Blob)rs.getBlob(1);  
  13.         if(blob!=null){  
  14.             //输出  
  15.             response.setContentType("image/jpeg");   
  16.             OutputStream outs = response.getOutputStream();  
  17.             InputStream pi = blob.getBinaryStream();  
  18.             int blobsize = (int)blob.length();  
  19.             byte[] blobbytes = new byte[blobsize];  
  20.             int bytesRead = 0;  
  21.             while ((bytesRead = pi.read(blobbytes)) != -1) {  
  22.                 outs.write(blobbytes, 0, bytesRead);  
  23.             }  
  24.             pi.close();  
  25.             outs.flush();  
  26.         }  
  27.         return null;  
  28.     }  
END
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值