从数据库中读取Blob 对象图片并显示 第一种方法: 大致方法就是,从数据库中读出 Blob 的流来,写到页面中去: Connection conn = DBManager
getConnection(); String sql = "SELECT picture FROM teacher WHERE id=1"; PreparedStatement ps = null; ResultSet rs = null; InputStream is = null; OutputStream os = null; try { ps = conn
prepareStatement(sql); rs = ps
executeQuery(); if(rs
next()){ is = rs
getBinaryStream(1); } response
setContentType("text/html"); os = response
getOutputStream(); int num; byte buf[] = new byte[1024]; while( (num=is
read(buf))
=-1 ){ os
write(buf, 0, num); } } catch (SQLException e) { e
printStackTrace(); } try { is
close(); os
close(); rs
close(); ps
close(); } catch (SQLException e) { e
printStackTrace(); } 在页面中: 搞定
第二种方法: 整个流程分为四步,连接 oracle 数据库 -> 读取 blob 图片字段 -> 对图片进行缩放 ->把图片展示在 jsp 页面上
import java
*; import java