建议读取时不要一次读取全部,可以调用dbms_lob包的有关功能实现分段读取。

解决方案 »

  1.   

    ResultSet rs= null;
    String szSQL="select clob_content from clob_t where seq=1";        
    rs =stmt.executeQuery(szSQL);
            Clob cContent =null;

            if(rs.next()) 
            {          cContent= rs.getClob(1);
              if (cContent != null)
              {        
                Reader is = cContent.getCharacterStream();
                BufferedReader br = new BufferedReader(is);
                
                String s = br.readLine();
                
                 while (s != null) 
                {
                    sReturn += s + "<br>";
                    s = br.readLine();
                }
               is.close();
               }
              
       
                        
     
    }
           
           
            rs.close();
          stmt.close();
          conn.close();
            
            
     out.println(sReturn);
      

  2.   

    后来我重新写了代码,将String变成了StringBuffer,问题得到了缓解,但是不知道,这种解决方法是否是最合适的?请大家赐教
    ResultSet rs= null;
    String szSQL="select clob_content from clob_t where seq=1";        
    rs =stmt.executeQuery(szSQL);
            Clob cContent =null;

            if(rs.next()) 
            {        cContent= rs.getClob(1);
              int tLen = (new Long(cContent.length())).intValue();
              String content = cContent.getSubString(1, tLen);
              
              StringBuffer str=new StringBuffer(tLen);
            
            boolean goonReplace = true ;
            int beginPos = 0 ;
            int endPos   = 0 ;
            
            
            int idPos    = 0 ;
            
            while (goonReplace) {
                beginPos = content.indexOf("\n",beginPos) ;
                if( beginPos!=-1)
                  { str=str.append(content.substring(0,beginPos)+"<br>");
                    content=content.substring(beginPos+1);
                    beginPos = 0 ;
                  }
                else
                  {
                    str=str.append(content);
                    goonReplace = false ;
                  }
             }
            
              
               
     out.println(str.toString()); }
           
           
            rs.close();
          stmt.close();
          conn.close();