I am trying to learn JasperReports on some online tutorial sites but I cant seem to make this simple snippet work.
I wanted to select a date field from my DB and pass it into my jrxml file.
<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="ToolDemo"
columnCount="2"
columnWidth="240" pageWidth="612" pageHeight="792">
<import value="java.util.Date"/>
<queryString>
<![CDATA[select a.id, a.date_acquired from tools a where a.country = 'Oceania']]>
</queryString>
<field name="id" class="java.lang.String"/>
<field name="date_acquired" class="java.util.Date"/>
But I cant get pass the filling process and I am having an error: Unable to get value for field date_acquired of class "java.util.Date". I tried making use of import tag also.
Any idea please?
I’ve copied your report template, create sample MySql database with one table
Then I inserted one row:
Test query:
After that I used your template and tested it under iReport tool. Just open you report using iReport.
Your report template with little modifications:
Using mysql database connection and report template i tested report generation under iReport and it works fine.
Are you sure that field “date_acquired” is type of DATE (or another format for dates in your database) in database? I recommend you to use iReport fore report template generation. It’s very useful and prevent you from writing a lot of “boring” code. Also, it could helps you to create report fields from sql query and test it using real database.