显示Lob类型的数据的,图片也可以用getBinaryStream的,你参考一下
<%
String BlobColumn = request.getParameter("BlobColumn");
String RowID = request.getParameter("RowID");
String BlobTable = BlobColumn.substring(0,BlobColumn.indexOf("."));
String BlobRow = BlobColumn.substring(0,BlobColumn.indexOf("&"));
String FileType = BlobColumn.substring(BlobColumn.lastIndexOf("&")+1);
//查询数据库
DatabaseManagement db = new DatabaseManagement();
ResultSet rs = null;
try
{
//生成查询语句
String SqlStr = "Select "+BlobRow
+" From "+BlobTable
+" Where "+BlobTable+".RowID="+"'"+RowID+"'";
System.out.println("CreatMisBlobSql="+SqlStr);
rs = db.runQuery(SqlStr);
OutputStream outFile=response.getOutputStream();
//设置打开方式
//response.setContentType("data/Application");
if (FileType.equals("XLS") ¦ ¦ FileType.equals("xls"))
{
response.setContentType("application/msexcel");
}
if (FileType.equals("DOC") ¦ ¦ FileType.equals("doc"))
{
response.setContentType("application/msword");
}
if (FileType.equals("PPT") ¦ ¦ FileType.equals("ppt"))
{
response.setContentType("application/mspowerpoint");
}
if (FileType.equals("PDF") ¦ ¦ FileType.equals("pdf"))
{
response.setContentType("application/pdf");
}
response.addHeader("content-type","application/msexcel");
response.addHeader("Content-Disposition", "attachment; filename=\"" + "Temp."+FileType + "\"");
if (rs.next())
{
InputStream inFile = rs.getBinaryStream(1);
int length=0;
int STREAM_SIZE = 1000000;
byte[] buffer = new byte[STREAM_SIZE];
while ((length = inFile.read(buffer)) != -1)
{
System.out.println("readed lenth = "+length);
outFile.write(buffer,0,length) ;
}
rs.close();
outFile.close();
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
db.closeConnection();
}
%>
<%
String BlobColumn = request.getParameter("BlobColumn");
String RowID = request.getParameter("RowID");
String BlobTable = BlobColumn.substring(0,BlobColumn.indexOf("."));
String BlobRow = BlobColumn.substring(0,BlobColumn.indexOf("&"));
String FileType = BlobColumn.substring(BlobColumn.lastIndexOf("&")+1);
//查询数据库
DatabaseManagement db = new DatabaseManagement();
ResultSet rs = null;
try
{
//生成查询语句
String SqlStr = "Select "+BlobRow
+" From "+BlobTable
+" Where "+BlobTable+".RowID="+"'"+RowID+"'";
System.out.println("CreatMisBlobSql="+SqlStr);
rs = db.runQuery(SqlStr);
OutputStream outFile=response.getOutputStream();
//设置打开方式
//response.setContentType("data/Application");
if (FileType.equals("XLS") ¦ ¦ FileType.equals("xls"))
{
response.setContentType("application/msexcel");
}
if (FileType.equals("DOC") ¦ ¦ FileType.equals("doc"))
{
response.setContentType("application/msword");
}
if (FileType.equals("PPT") ¦ ¦ FileType.equals("ppt"))
{
response.setContentType("application/mspowerpoint");
}
if (FileType.equals("PDF") ¦ ¦ FileType.equals("pdf"))
{
response.setContentType("application/pdf");
}
response.addHeader("content-type","application/msexcel");
response.addHeader("Content-Disposition", "attachment; filename=\"" + "Temp."+FileType + "\"");
if (rs.next())
{
InputStream inFile = rs.getBinaryStream(1);
int length=0;
int STREAM_SIZE = 1000000;
byte[] buffer = new byte[STREAM_SIZE];
while ((length = inFile.read(buffer)) != -1)
{
System.out.println("readed lenth = "+length);
outFile.write(buffer,0,length) ;
}
rs.close();
outFile.close();
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
db.closeConnection();
}
%>
<%@ page language="java" import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%
try {
String id=request.getParameter("id");
..//此处联数据库
String cmd="select image from news WHERE id ="+id;
PreparedStatement sql=con.prepareStatement(cmd);
ResultSet rs = sql.executeQuery();
rs.next();
InputStream in = rs.getBinaryStream("image");
response.reset();
response.setContentType("image/jpeg");
byte[] b = new byte[1024];
int len;
while((len=in.read(b)) >0)
response.getOutputStream().write(b,0,len);
in.close();
rs.close();
}
catch(Exception e)
{ out.println(e);}
%>
使用:
页面显示图片<img src="showImage.jsp?id=<%=id%>">
比如:
id size name path
01 800x600 美女 /img/001.jpg从数据库取出路径
......
path=rs.getString("path");
页面显示图片<img src="<%=path%>">