<%@ page import="java.util.Date,java.sql.*,com.brjl.database.*,oracle.sql.*"%>
<jsp:useBean id="param" scope="page" class="com.brjl.utils.ParamUtils"/>
<%
    int pictureId=param.getIntParameter(request,"picture_id",0);
    JdbcConnect myQuery=new JdbcConnect();
    ResultSet rs = myQuery.executeQuery("SELECT * FROM picture where picture_id="+pictureId);
       int length = 0;
       if (rs.next())       {
      BLOB my_blob = (BLOB)rs.getObject("picture");
      length = (int)my_blob.length();
      out.print(length);
      byte [] byte_array  = my_blob.getBytes(1, length);
      response.setContentType("image/jpeg");
    ServletOutputStream sos = response.getOutputStream();    for(int i=0;i<byte_array.length;i++)
    {
    sos.write(byte_array[i]);
    }
     sos.close();
    }   rs.close();
   myQuery.closeStmt();
   myQuery.closeConn();
  %>
这是一个oracle数据库的blob图片显示的例子,是用jsp作的。
调用方式:<img src="showimage.jsp?picture_id=<%=info_title_picture_id%>" width="150" height="128" border="0">

解决方案 »

  1.   

    错误信息;请问该如何解决?
    Syntax error in sourceNote: sun.tools.javac.Main has been deprecated.
    /test01.jsp.java:37: Class BLOB not found. (JSP page line 9)
          BLOB my_blob = (BLOB)rs.getObject("FILE");
          ^
    /test01.jsp.java:37: Class BLOB not found. (JSP page line 9)
          BLOB my_blob = (BLOB)rs.getObject("FILE");
                          ^
    /test01.jsp.java:38: Undefined variable: length (JSP page line 10)
          length = (int)my_blob.length();
          ^
    3 errors, 1 warning
      

  2.   

    你需要把oracle数据库驱动放到classpath中.
      

  3.   

    我的数据库是mysql,驱动已经在classpath中了!
      

  4.   

    应该用inStream = rs.getBinaryStream(1); 
    来获取字段的输入流,然后从输入流读取数据到输出流。
        ServletOutputStream sos = response.getOutputStream();
        byte b[] = new byte[1];
        while(inStream.read(b)!=-1)
        {
          sos.write(b);
        }
        sos.close();
        inStream.close();