【问题标题】:How to show blob object image using JasperReports from sqlite database? [duplicate]如何使用来自 sqlite 数据库的 JasperReports 显示 blob 对象图像? [复制]
【发布时间】:2017-02-18 08:43:04
【问题描述】:

我在我的应用程序中使用 ireport 工具。需要在报告中显示图像。我在数据库中有一个 blob 对象字段来存储图像。我需要在报告中将 blob 对象字段显示为图像。

但是,如果我检索除 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>

我收到此错误: "net.sf.jasperreports.engine.JRException: Unable to get value for result set field "image" of class java.io.InputStream"

有什么想法吗?

【问题讨论】:

标签: sqlite jasper-reports


【解决方案1】:

我找到了解决方案。解决问题的步骤:

  1. 将属性类型从 Blob 更改为 Binary
  2. 更改字段类型:&lt;field name="image" class="java.io.InputStream"/&gt;

【讨论】:

    【解决方案2】:

    同意@joyo。我按照他的榜样,它的工作。这是他的意思的完整示例(以防万一有人感兴趣):

    <?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>
    

    【讨论】:

    • 如果完整的例子感觉足够重要,最好作为评论选择的答案
    • 我认为完整的示例很有用。考虑编辑原始答案。
    猜你喜欢
    • 2019-07-01
    • 2015-05-03
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 2015-05-25
    • 2020-01-11
    • 1970-01-01
    • 2012-02-03
    相关资源
    最近更新 更多