db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Walding <...@walding.com>
Subject Re: clobs using torque and oracle
Date Thu, 30 Jan 2003 09:46:12 GMT
It can be done to an extent.

You have to modify village to understand the clob type, check back in 
the mailing list archives for more info.

Remember this though
Pure JDBC drivers (type 4 I think) can only read the first 4k of a clob.
OCI drivers work correctly.



priyapravas wrote:

>This is the problem with how Oracle stores the Large objects in the database. I don't
think this has got anything to do with torque. However I may be wrong. Here's a code snippet
(src: OTN (http://technet.oracle.com)) of how I read/wrote CLOBs to the database using JDBC
2.0 (Oracle's libraries). For more information you can check out the following link (registration
required blah blah...)
>http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oralob.htm#1043325
>
>
>================
>Reading BLOB:
>
>Use the getBinaryStream() method of the oracle.sql.BLOB class to read BLOB data. The getBinaryStream()
method reads the BLOB data into a binary stream.
>The following example uses the getBinaryStream() method to read BLOB data into a byte
stream and then reads the byte stream into a byte array (returning the number of bytes read,
as well).
>
>// Read BLOB data from BLOB locator.
>InputStream byte_stream = my_blob.getBinaryStream();
>byte [] byte_array = new byte [10];
>int bytes_read = byte_stream.read(byte_array);
>...
>
>=================
>
>=================
>Reading CLOB:
>
>The following example uses the getCharacterStream() method to read CLOB data into a Unicode
character stream. It then reads the character stream into a character array (returning the
number of characters read, as well).
>
>// Read CLOB data from CLOB locator into Reader char stream.
>Reader char_stream = my_clob.getCharacterStream();
>char [] char_array = new char [10];
>int chars_read = char_stream.read (char_array, 0, 10);
>...
>The next example uses the getAsciiStream() method of the oracle.sql.CLOB class to read
CLOB data into an ASCII character stream. It then reads the ASCII stream into a byte array
(returning the number of bytes read, as well).
>
>// Read CLOB data from CLOB locator into Input ASCII character stream
>Inputstream asciiChar_stream = my_clob.getAsciiStream(); 
>byte[] asciiChar_array = new byte[10]; 
>int asciiChar_read = asciiChar_stream.read(asciiChar_array,0,10);
>
>==================
>
>
>==================
>Wrting BLOB:
>Use the getBinaryOutputStream() method of an oracle.sql.BLOB object to write BLOB data.
>The following example reads a vector of data into a byte array, then uses the getBinaryOutputStream()
method to write an array of character data to a BLOB.
>
>java.io.OutputStream outstream;
>// read data into a byte array 
>byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
>// write the array of binary data to a BLOB
>outstream = ((BLOB)my_blob).getBinaryOutputStream();
>outstream.write(data);
>
>==================
>
>=================
>Writing CLOB:
>
>Use the getCharacterOutputStream() method or the getAsciiOutputStream() method to write
data to a CLOB. The getCharacterOutputStream() method returns a Unicode output stream; the
getAsciiOutputStream() method returns an ASCII output stream.
>The following example reads a vector of data into a character array, then uses the getCharacterOutputStream()
method to write the array of character data to a CLOB. The getCharacterOutputStream() method
returns a java.io.Writer instance in an oracle.sql.CLOB object, not a java.sql.Clob object.
>
>java.io.Writer writer;
>// read data into a character array
>char[] data = {'0','1','2','3','4','5','6','7','8','9'};
>// write the array of character data to a CLOB 
>writer = ((CLOB)my_clob).getCharacterOutputStream();
>writer.write(data);
>writer.flush();
>writer.close();
>...
>The next example reads a vector of data into a byte array, then uses the getAsciiOutputStream()
method to write the array of ASCII data to a CLOB. Because getAsciiOutputStream() returns
an ASCII output stream, you must cast the output to a oracle.sql.CLOB datatype.
>
>java.io.OutputStream out;
>// read data into a byte array
>byte[] data = {'0','1','2','3','4','5','6','7','8','9'};
>// write the array of ascii data to a CLOB 
>out = ((CLOB)clob).getAsciiOutputStream();
>out.write(data);
>out.flush();
>out.close();
>
>=================
>
>
>-PP 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: turbine-torque-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: turbine-torque-user-help@jakarta.apache.org
>
>
>  
>



Mime
View raw message