Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Java program to Convert java.lang.String to java.sql.CLOB Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java program to Convert java.lang.String to java.sql.CLOB Object" Watch "Java program to Convert java.lang.String to java.sql.CLOB Object" New topic
Author

Java program to Convert java.lang.String to java.sql.CLOB Object

anilellendula kumar
Ranch Hand

Joined: Jul 12, 2005
Posts: 43
Hai!


i am getting xml data as a string contain morethan 4kb size i am using thin driver oracle 9i database pls provide java programme to convert String to the java.sql.clob (not oracle.sql.clob)object to insert data in DB Table
anilellendula kumar
Ranch Hand

Joined: Jul 12, 2005
Posts: 43
here i tried with below code

long l=0;
oracle.sql.CLOB clobdocument=null;

try
{
Writer wr=clobdocument.setCharacterStream(l);
BufferedWriter br = new BufferedWriter(wr);
StringReader strrd=new StringReader(data);
char aux;
do{
aux=(char)strrd.read();
br.write(aux);
}while(aux != -1);


Giving Error

java.lang.reflect.InvocationTargetException: oracle.sql.CLOB.setCharacterStream(J)Ljava/io/Writer;


can anybobdy help how to Rectify this Problem,if my approach is wrong help me how convert String to Clob Object
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

java.sql.Clob is an interface so you can't instantiate it. I would use stmt.setAsciiStream rather than trying to create a CLOB. That way you don't have to use database specific code. It will still be stored as a CLOB in the database.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
anilellendula kumar
Ranch Hand

Joined: Jul 12, 2005
Posts: 43
My client requirement is to convert it to CLOB from string data and store in DB Table,can provide me logic to create CLOB object
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Originally posted by anilellendula kumar:
My client requirement is to convert it to CLOB from string data and store in DB Table,can provide me logic to create CLOB object

I think your client meant it should be stored as a CLOB in the database. How you go about that is an implementation detail.
Rohit Dhingraaa
Greenhorn

Joined: Jul 10, 2011
Posts: 4
Hi All,

I need to pass the Clob object in my junit test case to check the functionality.
How should I create the same?

Regards
Rohit Dhingra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java program to Convert java.lang.String to java.sql.CLOB Object
 
Similar Threads
How do I write a String to a java.sql.Clob
How to insert CLOB object into DB?
How to convert a java.sql.CLOB object to String
How to Convert a java.sql.CLOB object to String
Java program to Convert java.lang.String to java.sql.CLOB Object