如何在Jasper BLOB Image中显示?

时间:2016-12-21 11:32:27

标签: java oracle jsp

我正在尝试将图像添加到我的jasperReport中,但它确实有效,它会在调用时停止:

JasperRunManager.runReportToPdf ....

我在数据库中将图像作为BLOB类型,在“file.jrxml”中我将其设置为

字段 - > IMAGE_FILE

FIELDCLASS - > oracle.sql.blob。

和图像属性:

图像表达 - > $ F {} IMAGE_FILE .getBinaryStream()

表达式类 - > java.lang.String中

消息错误:

12:22:24,863 INFO  [STDOUT] 12:22:24,862 ERROR [JRFillSubreport] Fill 1: exception
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : $F{IMAGE_FILE}.getBinaryStream()
...
...
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'oracle.sql.BLOB@5d17f1ea' with class 'oracle.sql.BLOB' to class 'oracle.sql.BLOB'
at     org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)
...
...
12:22:24,863 ERROR [STDERR] net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : $F{IMAGE_FILE}.getBinaryStream()

所以主要错误无法解决,无法找到理由:

12:22:24,868 ERROR [STDERR] Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : $F{IMAGE_FILE}.getBinaryStream()
12:22:24,869 ERROR [STDERR] Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'oracle.sql.BLOB@5d17f1ea' with class 'oracle.sql.BLOB' to class 'oracle.sql.BLOB'

1 个答案:

答案 0 :(得分:1)

我找到了答案。只需修改这2个值,现在可以正常工作:

* field : IMAGE_FILE
* field Class : oracle.sql.inputStream

新图片属性:

*image expresion : $F{IMAGE_FILE}
*expression class : java.lang.String