為什莫從資料庫中取出的圖片不能顯示出來

lyojbuilder發表於2004-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();
%>
<p class="indent">


哪裡錯了呢?
多謝

相關文章