iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate GuideFigure 6-5Query dialogiReport does not need you to define a query in order to generate a report. In fact, iReport could obtain data records from a datasource that is not defined by a query execution. Regardless, here is where you define it. The language of the query can be oneof those items listed in the combo box on the top of the query dialog. UR supports the most common querylanguages:• SQL• HQL• EJBQL• Xpath• MDX (both the standard and XMLA-encapsulated versions)Let’s focus on SQL. If the selected data source is a JDBC connection, iReport will test the access connection to the data sourceas you define the query. This allows iReport to identify the fields using the query metadata in the result set. The design toollists the discovered fields in the bottom portion of the window. For each field, iReport determines the name and the Java typespecified for that field by the JDBC driver.A query that accesses one or more tables containing a large amount of data may require a long delay while iReport scans thedata source to discover field names. You may want to disable the Automatically Retrieve Fields option in order to quicklyfinish your query definition. When you have completed the query, click the Read Fields button in order to start the fieldsdiscovery scan.All fields used in a query must have a unique name. Use alias field names in the query for fields having the samename.In case of an error during the query execution (due to a syntax error or to an unavailable database connection), an errormessage will be displayed instead of the fields list.The field name scan may return a large number of field names if you are working with complex tables. I suggest that youreview the list of discovered names and remove any fields that you are not planning to use in your report, in order to reduceunnecessary complexity.When you click the OK button all the fields in the list will be included in the report design. You canalso remove them later in the outline view, but it’s a good idea at this point in the design process to remove any field namesthat you won’t be using.98

6.1.2 Accessing the SQL Query DesignerFields, Parameters, and VariablesiReport provides a simple visual query designer to help you create simple SQL queries without having to know a particularlanguage. You can access the tool by clicking the button labeled Query designer (a JDBC connection must be active, and theselected language of the query must be SQL).Figure 6-6SQLeonardo Query DesignerThis SQL query designer, which comes from the SQLeonardo open source project, provides a drag-and-drop way to createqueries (see Figure 6-6).To create a query you need to drag the required tables into the main panel. Check which fields you will need. The designerallows you to define table joins. To join two tables, drag the field of one table over the field of another. Edit the join type byright-clicking the red, square joint icon in the middle of the join line. To add a condition, right-click the Where node in thequery tree. To add a field to the Group By and Order By nodes, right-click a field under the SELECT node.6.1.3 Registration of the Fields of a JavaBeanOne of the most advanced features of UR is the ability to manage data sources that are not based on simple SQLqueries. One example of this is JavaBean collections. In a JavaBean collection, each item in the collection represents a record.UR assumes that all objects in the collection are instances of the same Java class. In this case the “fields” are theobject attributes (or even attributes of attributes).By selecting the JavaBean Datasource tab in the query designer, you can register the fields which correspond to the specifiedJava classes. The concept here is that you will know which Java classes correspond to the objects that you will be using in yourreport.99

6.1.2 Accessing the SQL Query DesignerFields, Parameters, and Variables<strong>iReport</strong> provides a simple visual query designer to help you create simple SQL queries without having to know a particularlanguage. You can access the tool by clicking the button labeled Query designer (a JDBC connection must be active, and theselected language of the query must be SQL).Figure 6-6SQLeonardo Query DesignerThis SQL query designer, which comes from the SQLeonardo open source project, provides a drag-and-drop way to createqueries (see Figure 6-6).To create a query you need to drag the required tables into the main panel. Check which fields you will need. The designerallows you to define table joins. To join two tables, drag the field of one table over the field of another. Edit the join type byright-clicking the red, square joint icon in the middle of the join line. To add a condition, right-click the Where node in thequery tree. To add a field to the Group By and Order By nodes, right-click a field under the SELECT node.6.1.3 Registration of the Fields of a JavaBeanOne of the most advanced features of UR is the ability to manage data sources that are not based on simple SQLqueries. One example of this is JavaBean collections. In a JavaBean collection, each item in the collection represents a record.UR assumes that all objects in the collection are instances of the same Java class. In this case the “fields” are theobject attributes (or even attributes of attributes).By selecting the JavaBean Datasource tab in the query designer, you can register the fields which correspond to the specifiedJava classes. The concept here is that you will know which Java classes correspond to the objects that you will be using in yourreport.99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!