• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read CLOB data from oracle database.

 
Chethan C Gowda
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell how to read CLOB data from oracle database. The below reflection method is not working

Clob clob = resultSet.getClob("clobdata");
Class clobClass = Class.forName("oracle.sql.CLOB");
Method bsv = clobClass.getMethod("binaryStreamValue", new Class[0]);
is = (InputStream) bsv.invoke(clob, new Object[0]);
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chethan,
I would use rs.getAsciiStream() rather than rs.getClob() to get the InputStream directly without going through reflection or an Oracle specific class.
 
Pavel Cherkashin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To treat clobs as easy string fields, set jdbc connection property
and enjoy.

Clob in oracle uses its own connection. When you retrieve clob ordinarily (the same to blob), you should use the api methods to access content as i/o steams.
Also take into your consideration the fact, that oracle uses one special type of clobs - empty clobs (and empty blobs as well).

And the last, if you prefer usage of oracle CLOB class, then cast java.sql.Clob to oracle.sql.CLOB and enjoy usage of oracle specific methods. Usage of reflection in jdbc is strongly discouraged
 
Chethan C Gowda
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne/Pavel

By changing Class.forName("oracle.sql.CLOB"); to clob.getClass() it worked.
Thanks for your help.

Clob clob = resultSet.getClob("clobdata");
Class clobClass = clob.getClass();
Method bsv = clobClass.getMethod("binaryStreamValue", new Class[0]);
is = (InputStream) bsv.invoke(clob, new Object[0]);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic