码迷,mamicode.com
首页 > 数据库 > 详细

img显示从数据库取出blob字段

时间:2017-06-06 18:43:43      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:resultset   rpe   head   put   oid   entity   20px   dmi   throws   

@RequestMapping("/getPictureForpeople")
public void getPictureForpeople(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
Connection conn = null;
conn = GetJDBCConnection.getJDBCConnection();
Statement stmt = conn.createStatement();
String getPicSQL = "select header from lc0039999.idmidentityinfo where code = ‘houzt‘";
ResultSet rs = stmt.executeQuery(getPicSQL);
Blob img=null;
if(rs.next()) {
img = rs.getBlob("header");
}
long size=img.length();
byte[] bs=img.getBytes(1, (int)size);
// response.setContentType("image/jpeg");
ServletOutputStream outs=response.getOutputStream();
outs.write(bs);
outs.flush();
}

<img src="${ctx}/PersonPages/getPictureForpeople" style="width: 100px;height:120px;border:5px solid #104365;clear: both; display: block; margin:auto; "/>

img显示从数据库取出blob字段

标签:resultset   rpe   head   put   oid   entity   20px   dmi   throws   

原文地址:http://www.cnblogs.com/zhanchigaofei/p/6952389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!