数据库中保存的是clob类型的流
读取方法如下:
<span style="white-space:pre"> </span>private void cxXP(HttpServletRequest request,HttpServletResponse response){
String userName = (String) request.getSession().getAttribute("username")==null?"":(String) request.getSession().getAttribute("username");
DBConnection db = null;
Connection dbCon = null;
Statement hdLSStmt = null; // 获得历史查询
ResultSet hdLSRs = null;
Reader reader = null;
try {
String HCHM = request.getParameter("ZJHM") == null ? "" : request.getParameter("ZJHM");
//String HCHM = request.getParameter("ZJHM") == null ? "" : request.getParameter("ZJHM").replace("\\", "/");
//HCHM = HCHM.toUpperCase();
db = new DBConnection("DataSource1");
dbCon = db.getConnection();
String sql = "select RWID,xp,length(xp) from QB_RW where RWID='" + HCHM+ "' and length(xp)>0 and rownum=1 ";
hdLSStmt = dbCon.createStatement();
hdLSRs = hdLSStmt.executeQuery(sql);
String xp = "";
byte[] xp_byte = null;
if (hdLSRs.next()) { // 说明以前查过该号码.并且是真号码
Clob clob_xp = hdLSRs.getClob("XP");
if (clob_xp != null) {
reader = clob_xp.getCharacterStream();
int l = (int) clob_xp.length();
char[] c = new char[l];
int length = 0;
while ((length = reader.read(c, 0, l)) != -1) {
xp += new String(c, 0, length);
}
}
if (reader != null) {
reader.close();
}
BASE64Decoder decode = new BASE64Decoder();
xp_byte = decode.decodeBuffer(xp);
}
if ("".equals(xp) && xp_byte == null) {
try {
String serverPath = request.getSession().getServletContext().getRealPath("/");
File f = new File(serverPath, "/img/wtp.jpg");
if (f.exists()) {
InputStream in = new FileInputStream(f);
xp_byte = new byte[in.available()];
in.read(xp_byte);
in.close();
} else {
xp_byte = new byte[0];
}
} catch (IOException e) {
xp_byte = new byte[0];
}
}
response.setContentType("image/gif");
response.getOutputStream().write(xp_byte);
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (IOException e) {
} catch (Exception e) {
Tools.errorList(e, userName);
} finally {
try {
if (hdLSRs != null) {hdLSRs.close();}
if (hdLSStmt != null) {hdLSStmt.close();}
if (dbCon != null) {dbCon.close();}
if (db != null) {db.close();}
} catch (Exception e) {
}
}
}
前台在extjs的grid列中显示:
<pre name="code" class="javascript"><span style="white-space:pre"> </span>{
header : "照片",
width : 110,
sortable : true,
dataIndex : 'RWID',
renderer : function(hm) {
return '<img src='+basePath+'servlet/front/LHXDS?type=cxXP&ZJHM='+hm+'&t='+new Date().getTime()+' width=100 height=100>';
}
}