`
z7swf
  • 浏览: 183534 次
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics