• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Need help on reading CLOB column

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate Code - Reading CLOB Data
----------------------------------------------------------------------------------------------------------------------------------
mapping.xml
-------------
<property name="clobData" type="clob">
<column name="ClobData" />
</property>

java code
---------
String clobHQL = "from ClobTest";
Query query = session.createQuery(clobHQL);

List result = query.list();

ClobPOJO clobPOJO = (ClobPOJO)result.get(0);
java.sql.Clob dataAsClob = clobPOJO.getClobData();

// FIRST WAY - Error
String dataAsString=dataAsClob.getSubString(1, (int) dataAsClob.length());

// SECOND WAY - Error
Reader reader=dataAsClob.getCharacterStream();
CharArrayWriter writer=new CharArrayWriter();
int i=-1;

while ( (i=reader.read())!=-1)
{
writer.write(i);
}

String dataAsString = new String(writer.toCharArray());


Error
========
java.io.IOException: [PWS0001] Function did not complete successfully.
at com.ibm.as400.access.AS400JDBCInputStream.read(AS400JDBCInputStream.java:305)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:200)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:239)
at java.io.BufferedInputStream.read(BufferedInputStream.java:294)
at com.ibm.as400.access.ConvTableReader.fillCache(ConvTableReader.java:180)
at com.ibm.as400.access.ConvTableReader.read(ConvTableReader.java:500)
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correction to HQL
String clobHQL = "from ClobPOJO";
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to get the data from CLOB. I had to made changes in the mapping and pojo to change the data type.
I changed the clob type to text (hibernate type) which is java equivalent "Very Long Strings"/java.lang.String.

mapping.xml
-------------
<property name="clobData" type="text/string">
<column name="ClobData" />
</property>

But, I am still unable to figure out why clob hibernate type is not supported. There is ClobImpl class and org.hibernate.type.ClobType
in hibernate but do not have enough time to run into hibernate jungle.

I hope i wont lose data using text/string.

Thanks
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ghulam, sorry if You explained it before...
What type is your clobData attribute of in your plain class?
I'm getting similar troubles with LONG type of Oracle.
Thanks
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In plain class (POJO) the data type is java.lang.String. And, in mapping it is text. But, this is for CLOB column.

Probably, for your LONG type you can map with big_decimal in mapping and in pojo you can use java.math.BigDeciml. Probably that may help.

Thanks
Rashid
 
And inside of my fortune cookie was this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic