[Java] Create a Simple Report by Jaspersoft Studio 6.1

[Java] Create a Simple Report by Jaspersoft Studio 6.1

Jaspersoft Studio is an Eclipse-based report designer for JasperReports Library and JasperReports Server; it’s available as an Eclipse plug-in or as a stand-alone application. Jaspersoft Studio allows you to create sophisticated layouts containing charts, images, subreports, crosstabs, and more. You can access your data through a variety of sources including JDBC, TableModels, JavaBeans, XML, Hibernate, Big Data (such as Hive), CSV, XML/A, as well as custom sources, then publish your reports as PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX, or OpenOffice. But my focus is on how to create a simple report and simple code.

I divided the task into two parts. First of all, create a Jasper template (*.jrxml) in Jaspersoft Studio. Secondly, write a simple code to generate report.

1. Double click “Sample DB” in “Repository Explorer” (on the left side), then set data-base and JDBC. Remember to click “Test” button. If your setting is correct, the window will display “Successful”. Finally, click “Finish”.

2. Create a new simple Jasper Report

3. Choose a report template, and click “Next”

4. Give it a file name

5. (1) Select “Simple DB” as data source that you have created already. (2) Write SQL statement. (3) Click “Next”

6. New report wizard will show you some fields name from your SQL statement. You can choose all of them if you need.

7. Congratulation! You’ve already created a Jasper Report successfully.

8. Click “Preview” tab (on the bottom), you should see tables. If you don’t see any table, you need to check your database connection.

Ok, let’s move to part 2. Before starting part 2, you need to prepare all libraries that related to JasperReport, you can download JasperReport library and read document from here.

1. (1) Create a Java project in Eclipse. (2) Copy JasperReport libraries to lib folder in Java project and set Java build path. (3) Create a folder to put *.jsxml. Your folder structure may looks like below:

2. Create a Java class.

public class FirstJasper {
    public static void main(String argv[]) {

    private static void reportFromDBTest() {
        Map m = new HashMap();
        String reportSource = "./jasper/FirstJasper.jrxml";
        String reportDest = "./jasper/report.pdf";

        try {
            // Data source
            Connection con = DriverManager

            JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, m, con);

            JasperExportManager.exportReportToPdfFile(jasperPrint, reportDest);
        } catch (JRException e) {
        } catch (ClassNotFoundException e1) {
        } catch (SQLException e2) {

3. Run java class, and you will see a report on your screen. That’s it!

(Visited 285 times, 1 visits today)

One thought on “[Java] Create a Simple Report by Jaspersoft Studio 6.1

Comments are closed.

Comments are closed.