Display CLOB in Jasper

岁酱吖の 提交于 2019-12-02 19:14:45

问题


My query in Jasper got CLOB data, but I'm not able to display it in my report, I even tried some of the solution that I found in this forum.

Both of these were not working:

new BufferedReader(new InputStreamReader($F{clob_data}.getAsciiStream())).readLine()


$F{clob_data}.getSubString( 1l, ( new Long( $F{clob_data}.length() ) ).intValue() )

even debug with no error, after run it in web application, it will show:

error=net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : ...
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to oracle.sql.CLOB

The CLOB field in my report:

<field name="clob_data" class="oracle.sql.CLOB"/>

And this is how I display my CLOB field:

<textFieldExpression class="java.lang.String"><![CDATA[$F{clob_data}.getSubString( 1l, ( new Long( $F{clob_data}.length() ) ).intValue() )]]></textFieldExpression>

<textFieldExpression class="java.lang.String"><![CDATA[new BufferedReader(new InputStreamReader($F{clob_data}.getAsciiStream())).readLine()]]></textFieldExpression>

There is no textFieldExpression for class="oracle.sql.CLOB"

Any easy way to handle this?

Update: My problem would be like this guy, still no solution:

http://iswwwup.com/t/1b800f433463/how-jasperreports-display-clob-field-with-html-tags.html


回答1:


Done. I found some trick to solve this unanswered problem. As we know Varchar2 only support 4000 of characters. So i came up with a trick to cut by part of my CLOB data in query like this:

select DBMS_LOB.SUBSTR(clob_field, 4000, 1) as clob_data_1 
select DBMS_LOB.SUBSTR(clob_field, 2000, 4001) as clob_data_2
from table

as you can see, i separately put my CLOB data in clob_data_1 and clob_data_2 so it still act as a String. In my case, i just used 6000 of characters. DBMS_LOB.SUBSTR is a oracle function to substring data.

In my report, i can simply combine this column just like this:

$F{clob_data_1}+$F{clob_data_2}

I hope with this solution, it can help some people that have similar problem like me.




回答2:


Try to make a String obiect from the CLOB either by appending "" or by calling String.valueOf()



来源:https://stackoverflow.com/questions/32001392/display-clob-in-jasper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!