• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
anilellendula kumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic