This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
Marshal
Posts: 38504
653
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]);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!