File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to Convert a java.sql.CLOB object to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to Convert a java.sql.CLOB object to String" Watch "How to Convert a java.sql.CLOB object to String" New topic

How to Convert a java.sql.CLOB object to String

Ankit Gandhi

Joined: Nov 03, 2006
Posts: 27

I have a PL/SQL procedure �reorganize_report� which returns a CLOB object. This proc is being called through a java file named in the following way-

csmt = con.prepareCall("{call report_spk.reorganize_report(?,?,?,?) }");

I am retrieving the Clob�s like this � (the CLOB object is of java.sql.CLOB class)
Clob sourcelocationLst = csmt.getClob(7);
Clob newlocationLst = csmt.getClob(8);
Clob fileNameLst = csmt.getClob(9);

Now I need to convert this CLOB into a String object.
I tried using the toString() function present for CLOB�s but it gives me the following o/p - oracle.sql.CLOB@66c9b250

Can anybody help me out with this?
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

If you look at the java.sql.Clob, there's a method called getCharacterStream() that returns a Reader. You can use the Reader and convert it into String.

Hope that helps.

SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
I agree. Here's the link:
subject: How to Convert a java.sql.CLOB object to String
It's not a secret anymore!