代码之家  ›  专栏  ›  技术社区  ›  Pablo Fernandez

ConversionException:Jasper报告上无法解析的日期

  •  0
  • Pablo Fernandez  · 技术社区  · 14 年前

    org.apache.commons.beanutils.ConversionException: Unparseable date: "03/03/1981"
            at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:241)
            at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBean.java:285)
            at net.sf.jasperreports.engine.data.JRAbstractTextDataSource.convertStringValue(JRAbstractTextDataSource.java:69)
            at net.sf.jasperreports.engine.data.JRXmlDataSource.getFieldValue(JRXmlDataSource.java:313)
            at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:823)
            at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:787)
            at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1478)
            at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:125)
            at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:942)
            at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:860)
            at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
            at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
            at XmlJasperInterface.report(XmlJasperInterface.java:89)
            at XmlJasperInterface.main(XmlJasperInterface.java:63)
    Caused by: java.text.ParseException: Unparseable date: "03/03/1981"
            at java.text.DateFormat.parse(DateFormat.java:337)
            at net.sf.jasperreports.engine.util.JRDateLocaleConverter.parse(JRDateLocaleConverter.java:84)
            at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:232)
            ... 13 more
    

    我找到一篇题为 BeanUtils, Digester, and Type Conversion

    String pattern = "MM/dd/yyyy";
    Locale locale = Locale.getDefault();
    DateLocaleConverter converter = new DateLocaleConverter(locale, pattern);
    converter.setLenient(true);
    ConvertUtils.register(converter, java.util.Date.class);
    

    但他们什么也没变。我还是会犯同样的错误。

    jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JRXmlDataSource(System.in, selectCriteria));
    

    谢谢。

    更新 :将Jasper Reports降级到1.1.0使它再次工作,因此很可能是升级破坏了它。

    1 回复  |  直到 12 年前
        1
  •  3
  •   Pablo Fernandez    14 年前

    您需要在数据源中设置一个日期模式,如下所示:

    JRXmlDataSource datasource = new JRXmlDataSource(....);
    datasource.setDatePattern("MM/dd/yyyy");