First, select the LOB locators into a standard result set, then get the LOB data into appropriate
Java classes:
// Select LOB locator into standard result set.
ResultSet rs =
stmt.executeQuery ("SELECT blob_col, clob_col FROM lob_table");
while (rs.next())
{
// Get LOB locators into Java wrapper classes.
java.sql.Blob blob = (java.sql.Blob)rs.getObject(1);
java.sql.Clob clob = (java.sql.Clob)rs.getObject(2);
(...process...)
}
If you have an OracleCallableStatement object ocs and a CLOB named my_clob, then input the CLOB to the stored procedure proc as follows:
OracleCallableStatement ocs =
(OracleCallableStatement)conn.prepareCall("{call proc(?))}");
ocs.setClob(1, my_clob);
ocs.execute();
To read from a CLOB, use the getAsciiStream() or getCharacterStream() method of an oracle.sql.CLOB object to retrieve the entire CLOB as an input stream. The getAsciiStream() method returns an ASCII input stream in a java.io.InputStream object. The getCharacterStream() method returns a Unicode input stream in a java.io.Reader object.
As with any InputStream or Reader object, use one of the overloaded read() methods to read the LOB data, and use the close() method when you finish.
You can also use the getSubString() method of oracle.sql.CLOB object to retrieve a subset of the CLOB as a character string of type java.lang.String.
To write to a CLOB, use the getAsciiOutputStream() or getCharacterOutputStream() method of an oracle.sql.CLOB object to retrieve the CLOB as an output stream to be written back to the CLOB. The getAsciiOutputStream() method returns an ASCII output stream in a java.io.OutputStream object. The getCharacterOutputStream() method returns a Unicode output stream in a java.io.Writer object.
As with any OutputStream or Writer object, use one of the overloaded write() methods to update the LOB data, and use the flush() and close() methods when you finish.
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);
Writing CLOB Data
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();
...
this 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();
hope it will be of some help
Prabhat kumar