Getting null values in Japer report

Hi,

I am new to jasper reports. i am created a report with the help of ireport and try to included in java code. In iReport the report was compiled and gives report with correct values. In the application it gives null values. 

The following is \the code i used ..

String queryString = "SELECT FIRSTNAME "
    + "FROM employee";
   stmt = con.createStatement();
   rset = stmt.executeQuery(queryString);
     List<HashMap<String, String>> dl = new ArrayList<HashMap<String, String>>();
             HashMap<String, String> hm;
             for(; rset.next(); dl.add(hm))
             {
                 hm = new HashMap<String, String>();
                 hm.put("FIRSTNAME", rset.getString("FIRSTNAME"));
                 System.out.println(rset.getString("FIRSTNAME"));

        } 
             JRBeanCollectionDataSource jrxmlds = new JRBeanCollectionDataSource(dl);
             java.util.Map parameters = new HashMap();
             String FileNamePath=path + "employee.jasper";
             net.sf.jasperreports.engine.JasperPrint jasperPrint = JasperFillManager.fillReport(FileNamePath, parameters, jrxmlds); // not added datasource elements (data) to jasperPrint

My Problem: 

I am getting the pdf report with null values. for this debugging the application . Iam getting the correct values

at datasource i.e. jrxmlds , but i am null values at jasperPrint . so please kindly help on this problem.

Code:
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
 
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
 
 
public class JasperDemoReport
{
 public static void main(String[] args) throws SQLException, FileNotFoundException,
 IllegalAccessException, ClassNotFoundException,Exception
 {
 
  final String driverClass = "com.mysql.jdbc.Driver";
  final String connectionURL = "jdbc:mysql://localhost:3306/sairamparcelservice";
  final String userID = "root";
  final String userPassword = "password";
  String path="C://ireportcompilation//";
  Connection con = null;
  Statement stmt = null;
  ResultSet rset = null;
  try
  {
 
   Class.forName(driverClass).newInstance();
   con = DriverManager.getConnection(connectionURL, userID, userPassword);
   String queryString = "SELECT FIRSTNAME "
    + "FROM employee";
   stmt = con.createStatement();
   rset = stmt.executeQuery(queryString);
     List<HashMap<String, String>> dl = new ArrayList<HashMap<String, String>>();
             HashMap<String, String> hm;
             for(; rset.next(); dl.add(hm))
             {
                 hm = new HashMap<String, String>();
                 hm.put("FIRSTNAME", rset.getString("FIRSTNAME"));
                 System.out.println(rset.getString("FIRSTNAME"));
 
        }  
             JRBeanCollectionDataSource jrxmlds = new JRBeanCollectionDataSource(dl);
             java.util.Map parameters = new HashMap();
             String FileNamePath=path + "employee.jasper";
             net.sf.jasperreports.engine.JasperPrint jasperPrint = JasperFillManager.fillReport(FileNamePath, parameters, jrxmlds); // not added datasource elements (data) to jasperPrint 
             String filename1 = "Report" + (new Date()).getTime() + ".pdf";
             JasperExportManager.exportReportToPdfFile(jasperPrint, path + "\\pdf\\" + filename1);
             System.out.println("Filename\t" + filename1);
         }
         finally
         {
             try
             {
              rset.close();
              stmt.close();
              con.close();
             }
             catch(Exception e1)
             {
                 System.out.println("Error in closing connection");
             }
         }
 
 }
 
}


Post Edited by nobel at 03/27/2010 04:07
nobel's picture
1
Joined: Mar 26 2010 - 8:28pm
Last seen: 13 years 6 months ago

0 Answers:

No answers yet
Feedback
randomness