Be careful that the detail fields actually end up in the detail section. If they end up in the column header the Preview WILL NOT work. You can verify field locations by looking at the Outline window as it is possible for the visual designer to be out of synch with where the field actually resides. You can drag fields from section to section using the Outline window.
1. Create a "Java->Java Desktop Application" project and name it "ireport". The "Choose Application Shell" should be "Database Application" select "Next".
2. Select "Table" from "Create Detail Area as:" and click "Finish".
3. Drag a button onto the designer left of the "New" button and change the text to "Run Report".
4. Right-click on the "Source Packages->ireport" node and choose "New->Other...". Select "Reports->JrxmlTemplate.jrxml" and name it "customerReport".
5. Click on the "Report Query" button.
6. In the "Report Query" view, enter the following and click "OK" (alternatively, you can use the Query Designer)
SELECT
CUSTOMER."NAME" AS CUSTOMER_NAME,
CUSTOMER."ZIP" AS CUSTOMER_ZIP,
CUSTOMER."ADDRESSLINE1" AS CUSTOMER_ADDRESSLINE1,
CUSTOMER."CITY" AS CUSTOMER_CITY,
CUSTOMER."STATE" AS CUSTOMER_STATE
FROM
"APP"."CUSTOMER" CUSTOMER
7. From the "Outline Window", expand the "Fields" node and drag and drop "NAME", "ADDRESSLINE1", "CITY", "STATE", and "ZIP" onto the designer "detail" section. The designer should look like the following snapshot.
8. From the "Palette" window, drag and drop a "static text" to the "column header" above the name field and type "Name" in the text.
9. From the "Palette" window, drag and drop a "static text" to the "column header" above the address details and type "Address" in the text.
10. For both the "static text" components, in the "Properties" window select "Bold" and change the font size to 16.
11. From the "Palette" window, drag and drop a "static text" to the "title" and type "Customer Address Report" in the text.
12. Change this static text to be bold and font size 24.
13. Tighten up the design by closing the gap from the bottom up between the sections.
14. Select the "Preview" view to generate the ".jasper" file.
| Explanation Point: The final design should look something like the follow snapshot. |
15. Right-click on the "ireport" project node and select "Properties".
16. Select "Categories:->Libraries". Add the following Libraries then select "OK".
17. Go back to "IReportView.java" "Design" view and double-click on the "Run Report" button.
18. In the "Set Action..." dialog make the following choices.
19. Click OK. Add the following code to the new "runReport" method.
try {
String reportName = "ireport/customerReport.jasper";
InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), conn);
JasperViewer jv = new JasperViewer(jasperPrint);
jv.setVisible(true);
} catch (ClassNotFoundException ex) {
Logger.getLogger(IreportView.class.getName()).log(Level.SEVERE, null, ex);
} catch (JRException ex) {
Logger.getLogger(IreportView.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(IreportView.class.getName()).log(Level.SEVERE, null, ex);
}
20. Run the application and press the "Run Report" button.
| commons-beanutils-1.7.jar | ![]() |
188671 bytes |
| commons-collections-2.1.jar | ![]() |
165119 bytes |
| commons-digester-1.7.jar | ![]() |
139966 bytes |
| commons-logging-1.0.2.jar | ![]() |
26388 bytes |
| ireport.zip | ![]() |
125934 bytes |
| ireport1.jpg | ![]() |
26984 bytes |
| ireport2.jpg | ![]() |
31000 bytes |
| ireport3.jpg | ![]() |
48366 bytes |
| ireport4.jpg | ![]() |
46889 bytes |
| ireport5.jpg | ![]() |
26582 bytes |
| jasperreports-2.0.4.jar | ![]() |
1922698 bytes |
| report query.jpg | ![]() |
5996 bytes |