| Different Size CLOB [message #92106] | 
			Wed, 10 March 2004 23:01   | 
		 
		
			
				
				
				
					
						
						Gianni
						 Messages: 7 Registered: November 2001 
						
					 | 
					Junior Member  | 
					 | 
		 
		 
	 | 
 
	
		Goodmorning experts, 
i have a big problem, and since two days that i'm not able to resolve it. 
i'm copying the content of a XML file into a CLOB. The problem is that at the end of the steps, into the CLOB field i have all structure but more of the original file. I don't know the cause. 
I put under the message a little code lines. Please can you help me.. My head is crazying. Thank you so much. 
Regards    Gianni 
--------------------------------- 
//*************Insert Value CLOB field ************ 
CLOB clob=((OracleResultSet)rs).getCLOB("FileXML"); 
writer=clob.getCharacterOutputStream(); 
final File fclob = new File(fileXML); 
is = new FileInputStream(fclob); 
final byte[[]] bufCLOB=new byte[[clob.getBufferSize()]]; 
bytesRead = 0; 
while((bytesRead = is.read(bufCLOB)) != -1) { 
	for (int i=0; i<bufCLOB.length;i++){ 
		writer.write(bufCLOB[[i]]); 
	} 
}						 
------------------------------------
		
		
		
 |  
	| 
		
	 | 
 
 
 | 
	
		
		
			| Re: Different Size CLOB [message #92120 is a reply to message #92106] | 
			Tue, 16 March 2004 21:50   | 
		 
		
			
				
				
				
					
						
						S_mim
						 Messages: 2 Registered: March 2004 
						
					 | 
					Junior Member  | 
					 | 
		 
		 
	 | 
 
	
		Try as Follows: 
 
I am collecting the content from clob into Temporary file. 
Just Modify the code as you want. 
  private String writeToFileReader(Clob clob) 
  { 
    String line, str = ""; 
    File tmpFile = null; 
    try 
    { 
      tmpFile = File.createTempFile("tmpDesc","xml"); 
      tmpFile.deleteOnExit(); 
 
      BufferedReader reader = new BufferedReader(clob.getCharacterStream()); 
      //FileWriter writer = new FileWriter(tmpFile); 
      while((line = reader.readLine()) != null) 
      { 
        str += line; 
      } 
      //writer.write(str); 
      OutputStream outStream = new FileOutputStream(tmpFile); 
      OutputStreamWriter out = new OutputStreamWriter(outStream,"UTF8"); 
      out.write(str); 
      out.close(); 
      // close all the stream 
      reader.close(); 
      //writer.close(); 
    }catch(IOException e) 
    { 
      System.out.println("IOException..from writeToFileReader.."+e.toString()); 
    }catch(SQLException se) 
    { 
      System.out.println("SQLException..from writeToFileReader.."+se.getMessage()); 
    } 
 
    if(tmpFile.length()!= -1) 
    { 
        return tmpFile.getPath(); 
    } 
        return "File NOt Found" ; 
  } 
Happy coding 
Shamim
		
		
		
 |  
	| 
		
	 | 
 
 
 |