为什莫从数据库中取出的图片不能显示出来

lyojbuilder 04-07-09

大家好:

我想把图片从数据库中读出来,显示在jsp页面上,但是一片空白,数据库中有图片的。

<%
ResultSet rs=null;
Statement stm=null;
Connection con=null;
String sql="select picture_file from building_picture";
response.setContentType(
"image/jpeg");
con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/fangtoo");
stm=con.createStatement();
rs=stm.executeQuery(sql);
int buffer = 1024;
// you should replace 1024 to another
// value meet your requirement
int index = -1;
byte[] b = new byte[buffer];

while(rs.next()) {
InputStream in = rs.getBinaryStream(1);

while ((index = in.read(b,0,buffer)) != -1){
out.println(b);
}

index = -1;
out.flush();
out.close();
}

rs.close();
stm.close();
con.close();
%>


哪里错了呢?
多谢

banq
2004-07-12 10:36

查一下资料:下面是我的写法:



response.setContentType("images/jpeg");
OutputStream toClient = response.getOutputStream();
try {

toClient.write(data);

} catch (Exception ex) {
Debug.logError(
"get the image error:" + ex, module);
} finally {
toClient.close();
}