thank u for ur help
Main Topics
Browse All Topics how to change a String to Clob,and how to change Clob
to String by java?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: schwertnerPosted on 2002-09-16 at 01:18:27ID: 7283399
Oracle provides some hints like this.
er( new oracle.jdbc.driver.OracleD river() ); n( "jdbc:oracle:thin:@s692:15 21:V816",
];
;
to write via a utString( (int)c_lob.length()+1, "\nBye!" );
Example demonstrating the use of the JDBC 2.0 Clob
and Blob classes. With the Oracle JDBC drivers version 8.1.6, these classes
can be used in place of oracle.sql.CLOB and oracle.sql.BLOB respectively.
The example requires the 8.1.6 JDBC driver (classes12.zip) to be used with
JDK version 1.2. The program is written to connect via the thin driver. You
need to update the connect string as appropriate for your database.
To run the program, first create the following table and data as scott/tiger:
create table test_lob (c1 number, c2 clob, c3 blob);
insert into test_lob values (10, 'This is some text for a clob column',
utl_raw.cast_to_raw('This is some text for a blob column'));
Then ensure that you have your CLASSPATH pointing to JDK1.2 and classes12.zip.
References
----------
"Oracle8i JDBC Developer's Guide and Reference", (A64685-01)
Source Code
-----------
/*
* This example uses the JDK 1.2 (JDBC 2.0) Clob and Blob classes. To
* build and run this program, you must use the 1.2 compiler and have the
* 8.1.6 JDBC driver with classes12.zip on your classpath (not
* classes111.zip).
*
* The example uses the following table and data:
*
* create table test_lob (c1 number, c2 clob, c3 blob);
*
* insert into test_lob values (10, 'This is some text for a clob column',
* utl_raw.cast_to_raw('This is some text for a blob column'));
*/
import java.sql.*;
import oracle.jdbc.driver.*;
import java.io.*;
public class selectLobs
{
public static void main ( String args [] ) throws SQLException
{
Connection conn;
String stmt;
Clob c_lob;
Blob b_lob;
Reader chr_instream; // Unicode clob reader
InputStream raw_instream; // Blob reader
char chr_buffer[]; // Clob buffer
byte raw_buffer[]; // Blob buffer
String out_buffer; // For binary -> String
// Select for update so we can also write data.
stmt = "select c1, c2, c3 from test_lob for update";
try
{
// Connect.
DriverManager.registerDriv
conn = DriverManager.getConnectio
"scott","tiger" );
// Turn off autocommit.
conn.setAutoCommit( false );
// Prepare the statement.
PreparedStatement pstmt = conn.prepareStatement( stmt );
// Execute.
ResultSet results = pstmt.executeQuery();
// Output the data.
results.next();
System.out.println( results.getInt( 1 ) );
// Get the Clob contents. Read as a single chunk using streaming.
// (If we were to read in a loop then we would read until -1 is
// returned.)
c_lob = results.getClob( 2 );
chr_buffer = new char[(int)c_lob.length()];
raw_buffer = new byte[(int)c_lob.length()*4
// First get as an ascii stream (byte array).
raw_instream = c_lob.getAsciiStream();
raw_instream.read( raw_buffer );
// Need to convert from a byte array to a String so can output.
out_buffer = new String( raw_buffer );
System.out.println( out_buffer );
raw_instream.close();
// Now get as a unicode stream.
chr_instream = c_lob.getCharacterStream()
chr_instream.read( chr_buffer );
System.out.println( chr_buffer );
chr_instream.close();
// Get the Blob contents.
b_lob = results.getBlob( 3 );
raw_buffer = new byte[(int)b_lob.length()];
// First via streaming as a single chunk.
raw_instream = b_lob.getBinaryStream();
raw_instream.read( raw_buffer );
out_buffer = new String( raw_buffer );
System.out.println( out_buffer );
raw_instream.close();
// Now directly as a byte array.
raw_buffer = b_lob.getBytes( 1, (int)b_lob.length() );
out_buffer = new String( raw_buffer );
System.out.println( out_buffer );
// Writing data to Lobs:
// There are no methods to do this with java.sql.Clob/Blob.
//
// For oracle.sql.CLOB there is getAsciiOutputStream() to write via
// an ascii stream and getCharacterOutputStream()
// unicode one, plus putChars() to write a char array and putString()
// to write a String - both at a given position within the Clob. For
// oracle.sql.BLOB there is getBinaryOutputStream() and putBytes().
// There are also oracle.jdbc.driver classes to do similar that
// take oracle.sql.CLOB/BLOB as appropriate, namely:
// OracleBlobOutputStream()
// OracleClobOutputStream()
// OracleClobWriter()
// (Note all three classes have corresponding input/reader classes.)
//
// Hence to write data to the lobs here it is necessary to cast the
// Clob and Blob to oracle.sql.CLOB and oracle.sql.BLOB respectively
// and use one of the methods listed above. E.g. to append to the
// clob column:
((oracle.sql.CLOB)c_lob).p
// To check the data has been input correctly read it back via the
// getSubString() method. Note, unlike CLOB, Clob has no getChars()
// method to return data as a char array.
System.out.println( c_lob.getSubString( 1, (int)c_lob.length() ) );
results.close();
pstmt.close();
// Commit.
conn.commit();
}
catch ( Exception e )
{
System.out.println( "\nError occurred:\n" + e + "\n" );
}
}
}
Sample Output
-------------
10
This is some text for a clob column
This is some text for a clob column
This is some text for a blob column
This is some text for a blob column
This is some text for a clob column
Bye!