• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to read CLOB data from oracle database.

 
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: 39341
755
Eclipse IDE VI Editor Java
  • 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]);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!