convert String to Clob

Mirinda used Ask the Experts™
I'd like to write an application in Java that write in a Table say myTable constructed as follow:
myTable (int primaryKey, Clob myClob).
The element to Insert in the Clob field is String which have more than 3000 characters.

How can I convert String to Clob?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Typically, the Clob class will be provided by the JDBC driver vendor. So converting a string into Clob depends on the API provided by the vendor.
For Oracle it is present in the Oracle.jar. Full classname is oracle.sql.CLOB

You create an instance of CLOB by
DBConnection connection = //get connection;
String s = //3000 chars;
oracle.sql.CLOB cl = new oracle.sql.CLOB(connection);
cl.putString(0, s);

Alternativley you could also write:
oracle.sql.CLOB cl = new oracle.sql.CLOB(connection, s.getBytes());

You retrieve the string by:
String s = cl.getSubString(0, cl.length());


Thanks gsatsan..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial