在Jasper中显示CLOB [英] Display CLOB in Jasper
问题描述
我在Jasper中的查询获得了CLOB数据,但是我无法在报告中显示它,甚至尝试了在该论坛中找到的一些解决方案。
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.
这两个都不起作用:
new BufferedReader(new InputStreamReader($F{clob_data}.getAsciiStream())).readLine()
$F{clob_data}.getSubString( 1l, ( new Long( $F{clob_data}.length() ) ).intValue() )
即使调试也没有错误,在Web应用程序中运行后,它将显示:
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
我的报告中的CLOB字段:
The CLOB field in my report:
<field name="clob_data" class="oracle.sql.CLOB"/>
这就是我显示我的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>
对于class = oracle.sql.CLOB,没有 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
推荐答案
完成。我发现了一些技巧来解决这个悬而未决的问题。
我们知道 Varchar2 仅支持4000个字符。所以我想出了一个技巧,可以像这样在查询中减少部分CLOB数据:
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
$ b中选择DBMS_LOB.SUBSTR(clob_field,2000,4001)as clob_data_2
如您所见,
$ b
我将我的CLOB数据分别放在clob_data_1和clob_data_2中,因此它仍然充当String。就我而言,我只使用了6000个字符。 DBMS_LOB.SUBSTR 是用于对数据进行子字符串化的oracle函数。
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.
这篇关于在Jasper中显示CLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!