Install Jaspersoft I-Reporter Designer
If Jasper not available on machine, it can be downloaded from here: http://www.jaspersoft.com
Connecting to Oracle Database
Jaspersoft Designer requires an Oracle Driver in order to connect to Oracle database using JDBC connection. The Oracle Driver can be downloaded here: http://www.oracle.com
The JDBC driver will be located in the sections under the Drivers section. For Oracle 11g, ojdbc6.jar will work.
After downloading ojdbc6.jar, move it in the following directory C:\Program Files\Jaspersoft\iReport-5.0.1\ireport\modules (this is assuming that installed the Designer in the default location).
Launch Jaspersoft Designer. Go to Tools -> Options. In the options section got to Classpath and click on Add Jar. Add the the odbc driver that was placed in C:\Program Files\Jaspersoft\iReport-5.0.1\ireport\modules. Click OK
Open the Jaspersoft Designer and create a new database connection by clicking on the database icon
NOTE: The following requires connection string. See support or appropriate department for access to your database string
JDBC connection for the Data source
- Click Next
- For JDBC driver choose Oracle(oracle.jdbc,driver.OracleDriver)
- NOTE: JDBC URL for Oracle has the following format -> jdbc:oracle:thin:@[HOST][:PORT]:SID
Enter Username and password the for the specific environment.
- Click Test to see if connection is valid, then click save
NOTE: Can add a database when creating a new Report in the Launch Report Wizard -> Connection / Data Source
Creating a Report using Database
NOTE: This section assumes the user has gone through the page "Install Jaspersoft I-Report Designer and Connect to Oracle DB". An assumption is made that the user also knows how to create business objects, rules, and use rule debugger.
Set up
Create a solution in AppBase and create a business object called Worker. Add the following attributes :
Name Type FName Text LName Text Age Number Position Text - Create a rule using Rule Generator that creates records for Worker , create_root_Worker
- Click Rule Generator and choose Create Object
- Select object Worker
- Select Age, Id, fname, lname, position
- Deploy Solution
Create records using rule debugger. For example
FName LName Age Position Jim Bob 23 QA Sarah Marshall 32 PM Kathy Macky 55 Engineer Jay Bob 56 Engineer
Create a New Report
- Open Jaspersoft Designer and connect to the environment where the business object was deployed
- To create a new report open Jaspersoft I-Report Designer, go to “File” -> “New”.“New File” window will pop up. Select “Report” icon from left side and you will see a list of report Templates.
Select one of the templates that you would like to create. Here you have two choices:- First to open Report Wizard. Report Wizard will ask you to define a SQL query.
- Second just to open a template. An empty report will be created and if you will need to create a SQL query later, you have to add it.
- Give it a name and click Finish.
- Now you’ll see an empty report with sections Title, Page Header, Column Header, etc. On this report you can add Text Field, Label, Grid, whatever you want and wherever you want on the report (position).
- On the left side of the Designer you can see a menu for the report containing Styles, Parameters, Fields, etc.
Create a Report With a Template
- To see this in action let us use one of the templates available. Go to “File” -> “New” -> “Coffee Landscape” and select this template for demonstration.
Here we can click “Open this Template” or “Launch Report Wizard” buttons. In this report template, we have grid, so we need to write a SQL query later, or we can click “Launch Report Wizard” button and configure a SQL query right away.
- Click “Launch Report Wizard” button, give report a name and location where it should be saved and click “Next”.
- On “Query” screen we should see you database connections if you added. If not, we can add a new connection from here and place our query in Query box.
Add the following Query for demonstration
Selecting all attributes from Tbl_WorkerSELECT * FROM Tbl_Worker
NOTE: If get Query Error Check SQL statement ( maybe remove ';' )
Include the following columns: fname, lname, age, position.
- The next section is the group by section which can be ignored at the moment.
- Click Finish to generate the Report
Jasper will generate three views
Name Description Designer This view allows user to modify arrangements and data in the report
XML This view gives experianced user same option of designing, but in XML form
Preview This gives view after design
More Technical Jasper Example
- To see this in action let us use one of the templates available. Go to “File” -> “New” -> “Coffee Landscape” and select this template for demonstration.
- Here we can click “Open this Template” or “Launch Report Wizard” buttons. In this report template, we have grid, so we need to write a SQL query later, or we can click “Launch Report Wizard” button and configure a SQL query right away.
- Click “Launch Report Wizard” button, give report a name and location where it should be saved and click “Next”.
- On “Query” screen we should see you database connections if you added. If not, we can add a new connection from here and place our query in Query box.
Let’s make a simple SQL query for demonstration. Let’s say we have a query like this
Simple QuerySELECT 'John' as FirstName, 'Smith' as LastName, 32 as Age FROM DUAL
- Place this query in “Query” section and click “Next”.
- Select fields that you want to populate on report. In this case let’s select all of them. Next is “Group by” clause which we don’t need in this simple SQL, so click “Next” and then “Finish”. Now we can see .jrxml report that has been created.
- Also please note that “FirstName”, “LastName” and “Age” that we defined above in SQL query, we can see those fields automatically added on report screen grid.
- So let’s get back to “Designer” screen. Here we can change element positions by moving them, delete elements, add another one, etc.
- On the left side we have a report menu.
- Expend “Fields” section, and we will see our three fields are there.
- From menu, select Fields, right click and we can add another field from there or delete.
- Parameter section has some default parameters that we cannot delete, but you can add parameters the same way like we add fields, variables, etc.
- We did not add anything yet or made some changes, so let’s click “Preview”button.
- Adobe Reader will pop up (if you have installed on your computer) and we will see PDF report.
- You can see from there that grid has three columns with header First Name, Last Name and Age and one record with values John, Smith, 32 as we mentioned in our SQL query.
- Now let’s do some modifications. For that purpose, go back to designer screen, select coffee picture on designer, right click and delete it.We also have coffee stain picture. Let’s delete that one also.
- Now let’s change the Title of the report. For that we can double click on Title from designer and change it from there or click on Title and on right side we can see “Properties” window with all available properties for this label including text, color, position, style, etc. Let’s change title label text to “Invoice” or whatever you want.
- Also let’s delete coffee sub title and Lorem ipsem text label. Now we have a simple report with Title and grid only. Click “Preview” and you will see how report looks like
- To be able to modify already created query, click on report name from the left Menu and on right side of designer we can see Report properties. There is section called “Query Text” and the value we can see our SQL query.
Open “Query Text”window (there is a small button next to the SQL query value). Add middle name to SQL so your query will look like something like this:
Simple QuerySELECT 'John' as FirstName, 'Smith' as LastName, 32 as Age, 'M' as MiddleName FROM DUAL
- Click OK. Now from Designer change the Age column width (header and field), make it smaller gently and add Middle Name column to the grid. For that you need to drug and drop label and put next to the Age header and change Text to “MiddleName”. Also same way add text field to the grid next to the Age field and change the Field Expression to “$F{MiddleName}”. Line up header and fields so grid will look nice and press “Preview” button
- To add a field on report we can simple drag and drop field from left menu on report wherever we want.
- Same way we can change the grid header by double clicking or single click and go to the properties section on the right. To be able to add another image, text field, label, table or any other element on report, go to “Window” à”Palette”. Again by drug and drop technique you can add elements on report and modify their properties as you wish.
- To add a parameter to report, select “Parameter” section from left menu, right click and “Add Parameter”. You will see parameter’s property window open on the right side. Give it name and type Name = InvoiceNumber, Parameter Class = java.lang.String
- Now drag and drop that parameter on the report anywhere you prefer.
- After adding parameter to report click “Preview” button and you can see that “Parameter prompt” window pops up so you can give it a value.
- Give a value and click OK and on Preview screen or In PDF you will see the value assigned to that parameter on the report.
- Same thing you can do by adding for example text field on report by drug drop from “Palette”, then click on that text field on the page, go to properties and assign “Text Field Expression” value to $P{InvoiceNumber}.
- Click Preview and you will get the same result.
- Add four more parameters of type string:
- Address
- City
- State
- Zip
Now add text field on report from “Palette”. In properties window for this text field let’s change “Text Field Expression” by clicking the small button next to the expression value.
- “Text Field Expression” window will pop up.
- From here we can select fields, parameters, variables that we want to populate on report for this particular text field.
- For now we can see that value for this text field is “$F{field}”. Let’s remove that. From this window we also see three columns.
- Please select “Parameters” from the left column. Middle column will show all available parameters for report. Here we want to populate Full address for this text field.
- Double click “Address” parameter and on top section of the window we can see that value “$P{Address}” has been added. Here we have some available functions.
Please find “concat()” function and double click on it. Make you the final expression looks like this $P{Address}.concat(',').concat($P{City}).concat(',').concat($P{State}).concat(',').concat($P{Zip})
- Click OK button and Preview report, give parameter values and we will see that our text field has the full address containing City, State and Zip values (Maybe for this example you need to change the text field width property, if your given address is too long, so you will be able to see full value of text field).