
2 在数据库有blob格式可以存放图片 以二进制流的方式取出来
<% String zjbm = CheckParam(request.getParameter("zjbm"),"") String zpSql = "select zp from tjjryxxx where sfzh = '"+zjbm+"'" out.clear() response.setContentType("image/jpeg") response.setHeader("Content-Transfer-Encoding","base64") Connection connection = null PreparedStatement ps = null ResultSet rs = null Blob blob =null byte[] data = null try{ connection =getConn() ps = connection.prepareStatement(zpSql) rs = ps.executeQuery() while(rs.next()){blob = (Blob)rs.getBlob("zp") long nlen = blob.length() int nsize = (int) nlen data = blob.getBytes(1,nsize) OutputStream out1 = response.getOutputStream() BufferedOutputStream bos =null bos = new BufferedOutputStream(out1) bos.write(data,0,data.length) bos.close() rs.close() } }catch(Exception e){ e.printStackTrace()} %>
这是用Struts做的<img src="<bean:write name="item" property="page"/>" width="100" height="100">
图片文件夹必须在服务器里
如果要存数据库的话,数据库存图片字段用blob形式的(照片:zp为例)。而且不能直接存,在存之前zp字段先插入一个empty.BLOB(),
然后select ZP from 表 for update。再用输入流的形式写进去。
// 先检索出来字段,必须使用oracle的类:oracle.sql.BLOB
oracle.sql.BLOB blob = null
if (rs.next())
{
blob = (oracle.sql.BLOB) rs.getBlob("ZP")
// 到数据库的输出流
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)