How to display CLOB (or BLOB) String in iReport?

blob, clob, ireport, jasper-reports, java

Solution

I had the same problem, and i found the following solutions.

First

one is placing the following statement in the `Textfield` expression. catch to this is the field should be free of carriage returns and line feeds to show the complete field value. I populate the field through `sql` query.

new BufferedReader(new InputStreamReader($F{FIELD_NAME})).readLine()

Second

creating a method in a class where in the `InputStream` is converted to `ByteArrayOutputStream` and converting it to `String` and then calling this method in the `Textfield` expression with `CLOB` value passed in.

In both cases the field should be declared as `java.io.InputStream`.

For more details.

Problem

I need to display a CLOB field with longer than 4000 characters in a text field using in iReport. I am using iReport version 5.5.0, I tried converting the CLOB to InputStream but it did not work, all I get is: ``` java.io.ByteArrayInputStream@43842a66 ``` I tried getSubString(long,int) but it only works for strings smaller than 4000 chars. stringValue() and toString() also did not work. Thanks for any help. EDIT: Clob.getSubString(long,int) method worked fine in my latter tests, I don't know why it didn't work before. So I used: ``` $F{FIELD}.getSubString( (long)1, (int)$F{FIELD}.length() ) ``` eventually. It may not be the best option, but I figured max length of a String (2147483647) is more than enough for the field.

Original source