数据库里存储照片的字段是Blob字段,实体定义为String类型,取出该图片并在页面显示 该怎么办

解决方案 »

  1.   

    实体定义成byte[]然后通过OutputStream 输入就好了。
      

  2.   

    实体定义private java.sql.Blob nr;
    读取Blob image =读取数据库的blog;//附件扫描图片
    if (image != null) {
    try {         
    byte[] buf = new byte[(int)image.length()];
    buf = image.getBytes(1, (int) image.length());
    BufferedInputStream pi = new  BufferedInputStream(image.getBinaryStream()); 
    response.setContentType("image/jpeg;");
    ServletOutputStream out = response.getOutputStream();
    response.setContentLength(pi.available());
    response.reset();
    int bytesRead = 0;     
    while((bytesRead = pi.read(buf)) != -1)   {     
    out.write(buf, 0, bytesRead);     
    }     
    pi.close();     
    out.flush();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
      

  3.   

    不用把图片存到数据库,不符合规划,数据库存图片路径,名称数据库是Blob就要用Blob类型读取