问题
I am using ireport tool in my application. There is a requirement to show the image on report. I have a blob object field in the database to store image. I need to show the blob object field as an image in the report.
However, it working fine if I retrieve any other data except Blob
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4_2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6bf1e8fc-5bd2-495a-abca-8c4d501c73af">
<queryString><![CDATA[SELECT image FROM myimage]]></queryString>
<field name="image" class="java.io.InputStream"/>
<detail>
<band height="125" splitType="Stretch">
<image>
<reportElement x="130" y="20" width="310" height="88" uuid="8b07de5d-ac9e-4245-9ca1-ccd6fd3fe993"/>
<imageExpression><![CDATA[$F{image}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
I'm getting this error:
"net.sf.jasperreports.engine.JRException: Unable to get value for result set field "image" of class java.io.InputStream"
Have any idea?
回答1:
I found the solution. Steps to fix issue:
- Change the type of attribute from Blob to Binary
- Change type of a field:
<field name="image" class="java.io.InputStream"/>
回答2:
Agreed with @joyo. I followed his example and it worked. Here is a complete example of what he meant (just in case anyone is interested):
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="38e603dd-e931-410d-b545-b16f01f0b6a8">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from rcis.invoice_print]]>
</queryString>
<field name="ORG_LOGO" class="java.io.InputStream"/>
<detail>
<band height="125" splitType="Stretch">
<image>
<reportElement x="168" y="23" width="100" height="50" uuid="dab25674-c16b-4866-88d0-c97695108f60"/>
<imageExpression><![CDATA[$F{ORG_LOGO}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
来源:https://stackoverflow.com/questions/42313024/how-to-show-blob-object-image-using-jasperreports-from-sqlite-database