Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to read CLOB data from oracle database.  RSS feed

 
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]);
 
author & internet detective
Posts: 38909
684
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.
 
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
Boost this thread!