title: Filling data into .jasper file from a java program
body: <p>Below is my bean class used for creating table and mappings using hibernate :</p>
  
  <pre><code>package org.jasperreports.entitiy;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity(name="User_table")  
  public class User {
   @Id  
   private int userId;  
   @Column(name="User_Name")  
   private String userName;  
   private  String userMessage;  
  
   public int getUserId() {  
    return userId;  
   }  
   public void setUserId(int userId) {  
    this.userId = userId;  
   }  
   public String getUserName() {  
    return userName;  
   }  
   public void setUserName(String userName) {  
    this.userName = userName;  
   }  
   public String getUserMessage() {  
    return userMessage;  
   }  
   public void setUserMessage(String userMessage) {  
    this.userMessage = userMessage;  
   }  
  </code></pre>
  
  <p>}</p>
  
  <p>This will create a table in the database named user_table</p>
  
  <p>Below is my class that I am using to generate a report</p>
  
  <pre><code>public class JasperReportTest {
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "jaspersoft";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root";
  String password = "root";
  String fileName = "C://JasperSoft/MyReports/sample2.jasper";
  String outFileNamePDF = "C://JasperSoft/MyReports/sample2.pdf";
  
  public JasperReportTest() {
      super();
  }
  
  @SuppressWarnings("deprecation")
  public void generateReport(HashMap hm) {
      try {
          Class.forName(driver).newInstance();
          conn = DriverManager
                  .getConnection(url + dbName, userName, password);
          System.out.println("Connected to the database");
          System.out.println("Filling report...");
          // used for synchronization between database and source file.
          JasperPrint print = JasperFillManager.fillReport(fileName, hm, conn);
          System.out.println(conn);
          // define and initialize jasperreport engine's exporter for .pdf
          JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
          // parameter used for the destined file.
  
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
          exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
                  outFileNamePDF);
          // export to .pdf
          exporter.exportReport();
  
  
          System.out.println("Created file: " + outFileNamePDF);
          System.out.println("Done!");
          conn.close();
      } catch (JRException e) {
          e.printStackTrace();
      } catch (SQLException e) {
          e.printStackTrace();
      } catch (InstantiationException e) {
          e.printStackTrace();
      } catch (IllegalAccessException e) {
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      }
  }
  
  public static void main(String[] args) {
        Configuration configuration=new Configuration();  
        configuration.configure();  
        ServiceRegistry sr= new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();  
        SessionFactory sf=configuration.buildSessionFactory(sr);  
        Session ss=sf.openSession();
  
          Query q = ss.createQuery("FROM org.jasperreports.entitiy.User");
  
          List results = q.list();
          HashMap hm = new HashMap();
          hm.put("userId", ((User) results.get(1)).getUserId()); //or else hm.put("EmployeeId", args[o]);
          hm.put("userMessage",((User) results.get(1)).getUserMessage());// or else hm.put("EmployeeName", args[1]);
          hm.put("User_Name",((User) results.get(1)).getUserName());//or else 
  
          new JasperReportTest().generateReport(hm);
  
          System.exit(1);
          }
          }
  </code></pre>
  
  <p>Below is my .jrxml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 5.6.2.final using JasperReports Library version 5.6.1  --&gt;
  &lt;!-- 2014-10-15T20:22:18 --&gt;
  &lt;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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="959ae434-7516-46d9-a6ab-69e707496d67"&gt;
  &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/&gt;
  &lt;parameter name="userId" class="java.lang.String"/&gt;
  &lt;parameter name="userMessage" class="java.lang.String"/&gt;
  &lt;parameter name="User_Name" class="java.lang.String"/&gt;
  &lt;queryString&gt;
      &lt;![CDATA[]]&gt;
  &lt;/queryString&gt;
  &lt;background&gt;
      &lt;band splitType="Stretch"/&gt;
  &lt;/background&gt;
  &lt;title&gt;
      &lt;band height="79" splitType="Stretch"/&gt;
  &lt;/title&gt;
  &lt;pageHeader&gt;
      &lt;band height="35" splitType="Stretch"/&gt;
  &lt;/pageHeader&gt;
  &lt;columnHeader&gt;
      &lt;band height="61" splitType="Stretch"&gt;
          &lt;staticText&gt;
              &lt;reportElement x="414" y="3" width="121" height="15" uuid="0cb2ba8e-4186-4173-8918-4b88c8b94af5"/&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font isBold="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[$P{userId}]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="3" width="136" height="15" uuid="e2ff7b5d-3a68-42a6-8160-15e3ef9f3e86"/&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font isBold="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[$P{userMessage}]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement x="200" y="3" width="136" height="15" uuid="22f30ae2-bc4a-4885-892b-7260c4d94474"/&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font isBold="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[$P{User_Name}]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
      &lt;/band&gt;
  &lt;/columnHeader&gt;
  &lt;detail&gt;
      &lt;band height="125" splitType="Stretch"/&gt;
  &lt;/detail&gt;
  &lt;columnFooter&gt;
      &lt;band height="45" splitType="Stretch"/&gt;
  &lt;/columnFooter&gt;
  &lt;pageFooter&gt;
      &lt;band height="54" splitType="Stretch"/&gt;
  &lt;/pageFooter&gt;
  &lt;summary&gt;
      &lt;band height="42" splitType="Stretch"/&gt;
  &lt;/summary&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>I am not so familiar with the API here so I assumed that the keys that we are putting into the hashmap automatically maps to the column headers fields I created in the .jasper file and insert the corresponding values under them.</p>
  
  <p>When I run the program it is generating an empty pdf file. Can anyone help me find the problem here.</p>
  
  <p>** Note : The .jasper file i am using as input file is an empty file that only contains column header fields. </p>