Domanda

I'm trying to import net.sf.jasperreports.engine.export to export all the details of cars (number, client, constructor, type, color ..). All the information is stored in the database.

In fact, I have succeeded to generate different types of files (XML, doc, docx, pdf ..), the name were named correctly, the size is set to A4 and files can be located in the right location. But all of the lines are empty, and I want to fill the data inside. I would like to use the method fill() and use JasperFillManager in order to fill the blanks. But it doesn't work. I don't know how to use JasperFillManager in order to find all of the information. Could someone help me?

  /**
 * Initializes this method. 
 * 
 * @param model
 * @param pageType
 * @param orientation
 * @param outputType
 * @param destination
 */
private void init(ExportModel model, PAGE_TYPE pageType, 
        PAGE_ORIENTATION orientation,  OUTPUT_TYPE outputType,
        String destination){
    this.model = model;
    this.printerData = new PrinterData();
    this.printerData.setUseSql(false);
    this.printerData.setPageFormat(pageType);
    this.printerData.setPageOrientation(orientation);
    this.printerData.setOutputType(outputType);
    this.printerData.setDestination(destination);

}

This is the initial of the class. I would like to write a function:

   public static void fill()
{
    try
    {
        JasperFillManager.fillReportToFile("static.jasper",null,new JREmptyDataSource());   

    } catch(JRException e)
    {
        e.printStackTrace();
    }
}

}

Thank you very much! If there is some sample code that would be better!

È stato utile?

Soluzione

You are passing a JREmptyDataSource to the fill manager. This is quite literally passing no data to the report. You should use one of the other data sources, probably a JRResultSetDataSource. You can get an overview of the commonly used data sources here: link.

If you have already queried your database and obtained a java.sql.ResultSet, you can use it to construct a JRResultSetDataSource and pass that to the fill manager instead.

Alternatively, you can pass the database connection (as a java.sql.Connection) to the fill manager and put your SQL query in the report design.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top