2015-10-27 27 views
0

我想導出我的數據表,因爲我使用JasperReport, 但它不起作用。 我得到這個錯誤:JasperReports連接

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean 

你能不能幫我請。

<?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="null" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" 
      leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" > 
<style name="Title" fontName="Times New Roman" fontSize="50" isBold="true" pdfFontName="Times-Bold"/> 
<style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/> 
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/> 
<style name="Detail" fontName="Arial" fontSize="12"/> 
<style name="Row" mode="Transparent"> 
    <conditionalStyle> 
     <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression> 
     <style backcolor="#E6DAC3"/> 
    </conditionalStyle> 
</style> 
<queryString language="HQL"> 
    <![CDATA[SELECT 
article.`CODE_ARTICLE` AS article_CODE_ARTICLE, 
article.`DESIGNATIONAL` AS article_DESIGNATIONAL, 
article.`DESIGNATIONFR` AS article_DESIGNATIONFR 
FROM 
`article` article]]> 
</queryString> 
<field name="article_CODE_ARTICLE" class="java.lang.String"/> 
<field name="article_DESIGNATIONAL" class="java.lang.String"/> 
<field name="article_DESIGNATIONFR" class="java.lang.String"/> 
<background> 
    <band splitType="Stretch"/> 
</background> 
<title> 
    <band height="136" splitType="Stretch"> 

     <staticText> 
      <reportElement style="Title" x="270" y="0" width="263" height="62"/> 
      <textElement verticalAlignment="Middle"> 
       <font pdfFontName="Times-Roman"/> 
      </textElement> 
      <text><![CDATA[Articles]]></text> 
     </staticText> 



    </band> 
</title> 
<pageHeader> 
    <band splitType="Stretch"/> 
</pageHeader> 
<columnHeader> 
    <band height="16" splitType="Stretch"> 
     <line> 
      <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="802" height="1" /> 
      <graphicElement> 
       <pen lineWidth="0.5" lineColor="#999999"/> 
      </graphicElement> 
     </line> 
     <staticText> 
      <reportElement style="Column header" x="0" y="0" width="267" height="15" forecolor="#736343" /> 
      <text><![CDATA[article_CODE_ARTICLE]]></text> 
     </staticText> 
     <staticText> 
      <reportElement style="Column header" x="267" y="0" width="267" height="15" forecolor="#736343" /> 
      <text><![CDATA[article_DESIGNATIONAL]]></text> 
     </staticText> 
     <staticText> 
      <reportElement style="Column header" x="534" y="0" width="267" height="15" forecolor="#736343" /> 
      <text><![CDATA[article_DESIGNATIONFR]]></text> 
     </staticText> 
    </band> 
</columnHeader> 
<detail> 
    <band height="15" splitType="Stretch"> 
     <frame> 
      <reportElement style="Row" mode="Opaque" x="0" y="0" width="802" height="15"/> 
      <textField isStretchWithOverflow="true"> 
       <reportElement style="Detail" x="0" y="0" width="267" height="15"/> 
       <textFieldExpression><![CDATA[$F{article_CODE_ARTICLE}]]></textFieldExpression> 
      </textField> 
      <textField isStretchWithOverflow="true"> 
       <reportElement style="Detail" x="267" y="0" width="267" height="15"/> 
       <textFieldExpression><![CDATA[$F{article_DESIGNATIONAL}]]></textFieldExpression> 
      </textField> 
      <textField isStretchWithOverflow="true"> 
       <reportElement style="Detail" x="534" y="0" width="267" height="15"/> 
       <textFieldExpression><![CDATA[$F{article_DESIGNATIONFR}]]></textFieldExpression> 
      </textField> 
     </frame> 
    </band> 
</detail> 
<columnFooter> 
    <band height="6" splitType="Stretch"> 
     <line> 
      <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="802" height="1" /> 
      <graphicElement> 
       <pen lineWidth="0.5" lineColor="#999999"/> 
      </graphicElement> 
     </line> 
    </band> 
</columnFooter> 
<pageFooter> 
    <band height="25" splitType="Stretch"> 
     <frame> 
      <reportElement mode="Opaque" x="-21" y="1" width="843" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" /> 
      <textField evaluationTime="Report"> 
       <reportElement style="Column header" x="783" y="1" width="40" height="20" forecolor="#736343" /> 
       <textElement verticalAlignment="Middle"> 
        <font size="10" isBold="false"/> 
       </textElement> 
       <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement style="Column header" x="703" y="1" width="80" height="20" forecolor="#736343" /> 
       <textElement textAlignment="Right" verticalAlignment="Middle"> 
        <font size="10" isBold="false"/> 
       </textElement> 
       <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> 
      </textField> 
      <textField pattern="EEEEE dd MMMMM yyyy"> 
       <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343"/> 
       <textElement verticalAlignment="Middle"> 
        <font size="10" isBold="false"/> 
       </textElement> 
       <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> 
      </textField> 
     </frame> 
    </band> 
</pageFooter> 
<summary> 
    <band splitType="Stretch"/> 
</summary> 

,這是我的函數:

public void test(){ 
     JasperReport jasperReport; 
JasperPrint jasperPrint; 
try 
{ 
    jasperReport = JasperCompileManager.compileReport(
     "C:/soprocess/ExportModel/report1.jrxml"); 
     JRBeanCollectionDataSource beanColDataSource = 
    new JRBeanCollectionDataSource(articleDAO.findAll()); 
    jasperPrint = JasperFillManager.fillReport(
     jasperReport, new HashMap(),beanColDataSource); 
    JasperExportManager.exportReportToPdfFile(
     jasperPrint, "C:/soprocess/ExportModel/simple_report.pdf"); 
} 
catch (JRException e) 
{ 
    e.printStackTrace(); 
} 

回答

0

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean 

是當碧玉報告不能與字段的名稱訪問公共getter方法拋出在你作爲數據源傳遞的bean中。

您必須在bean通過articleDAO.findAll()方法的相似傳遞給

public String getArticle_CODE_ARTICLE(){//your code} 
public String getArticle_DESIGNATIONAL(){//your code} 
public String getArticle_DESIGNATIONFR(){//your code} 

,因爲你有這些領域

<field name="article_CODE_ARTICLE" class="java.lang.String"/> 
<field name="article_DESIGNATIONAL" class="java.lang.String"/> 
<field name="article_DESIGNATIONFR" class="java.lang.String"/> 

需要注意的是:

<queryString language="HQL"> 
<![CDATA[SELECT 
article.`CODE_ARTICLE` AS article_CODE_ARTICLE, 
article.`DESIGNATIONAL` AS article_DESIGNATIONAL, 
article.`DESIGNATIONFR` AS article_DESIGNATIONFR 
FROM 
`article` article]]> 
</queryString> 

,因爲不考慮如果你喜歡我,你傳遞JRBeanCollectionDataSource噸被認爲你需要通過Hibernate Connection而不是(與碧玉報告的其他配置,以瞭解你的映射)。

+0

thx man這是我的問題(y) – user4386582