如何读取从ORACLE库中BLOB字段并显示到页面上去啊????
昨天发了一个帖,有个朋友给了段代码我,但我试了下,咋也读不出来.
帮忙看看:
写入的代码:
  ResultSet rs;String infile = "index.jsp";
/* 设定不自动提交 */
boolean defaultCommit = sqlConn.getAutoCommit();
sqlConn.setAutoCommit(false);
/* 插入一个空的BLOB对象 */
sqlStmt.executeUpdate("INSERT INTO documents(text,title,author,depart,checker,v_cout) VALUES (EMPTY_BLOB(),'全都是笨蛋','猪头','猪头部','老猪头',23)");
/* 查询此BLOB对象并锁定 */
rs = sqlStmt.executeQuery("SELECT text FROM documents WHERE title='全都是笨蛋' FOR UPDATE");
while (rs.next()) {
/* 取出此BLOB对象 */
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("text");
/* 向BLOB对象中写入数据 */
BufferedOutputStream outfile = new BufferedOutputStream(blob.getBinaryOutputStream());
StringBufferInputStream infile1 = new StringBufferInputStream(infile);
int c;
while ((c=infile1.read())!=-1) {
outfile.write(c);
}
}
sqlConn.commit();
读的代码:
  boolean defaultCommit = sqlConn.getAutoCommit();
  sqlConn.setAutoCommit(false);     String id = (String)request.getParameter("docu_id");
//integer.parseInt(id);
    String sql="select * from documents where DOCU_ID="+id;
  ResultSet rs=sqlStmt.executeQuery(sql);
  if(!rs.next())
  {
 out.println("文章不存在!");
  }
String str;
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("text");
InputStream stream = blob.getBinaryStream();
        OutputStream os = response.getOutputStream();
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
         os.write(buffer, 0, bytesRead);
 os.flush();
 out.println((String)buffer);
        }
}
%>帮我看看问题到底在哪里啊?
执行不出错,但就是写了读不出来.
帮我改改,谢谢各位了!!!