Question

I have a MySQL database named test-3 and only one table named student. The table structure is like this:

CREATE TABLE `student` (
`student_id` int(11) NOT NULL AUTO_INCREMENT,
`student_name` varchar(50) NOT NULL,
`nationality` varchar(255) NOT NULL,
`department` varchar(30) NOT NULL,
`fathers_name` varchar(50) DEFAULT NULL,
`mothers_name` varchar(50) DEFAULT NULL,
 PRIMARY KEY (`student_id`)
 ) 

So now, I want to create a report in iReport 5.5.0, I right-clicked on my report name, selected the option Add Dataset, then created a new datasource and named it as data. I selected MySQL from the dropdown list, selected the database, made the MySQL connection and it went successful. So far, so good. Now, I have designed my report structure previously, and I have also dragged the table into my report using the drag-and-drop option in iReport (selecting field from the dataset and then drag-and-drop into the report). But whenever I click the Preview button, I get the following message:

 net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :       
 1. Field not found : student_name      
 2. Field not found : nationality      
 3. Field not found : department

And my report is not loaded.

The SQL Query I ran to retrieve the resultset was this:

  select student_name, nationality, department 
  from student

Can anyone please explain where the problem is? I am absolutely a newby to JasperReports and iReport.

Was it helpful?

Solution

First of all, you have to declare the fields you retrieve from the database in your report. From your example, I suppose the fields are student_name, nationality and department, all of them should have the class set to java.lang.String, since they are all varchars. Your field declaration should look like this:

<field name="department" class="java.lang.String"/>

You will then be able to use them like $F{fieln_name}.

Now, I suppose you want to see the result data in a table. In this case, you will have declare the fields in the TableDataset and then just put a TextField in a cell and set its TextField expression to something like $F{department}.

Also, for this case, make sure to put the query in the TableDataset, not in the main dataset of the report.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top