iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide170
Data Sources and Query ExecutersCHAPTER 11 DATA SOURCES AND QUERY EXECUTERSThere are several ways that UR can provide data to fill a report. For example, you can put an SQL query directlyinside a report and provide a connection to a database against which to execute the query and read the resulting record set, oryou can use a more sophisticated custom technology to provide a table-like set of values.iReport provides direct support for a rich set of query languages, including SQL, HQL, EJBQL, and MDX, and supports otherlanguages like XPath (XML Path Language). Moreover, in iReport, you can use custom languages by registering plug-inengines called query executors to interpret and execute the report query.If you don’t want to use a query language, or you simply don’t want to put the query inside a report, you can use a URdata source. Basically, a JR data source is an object that iterates on a record set that is organized like a simpletable.All the data sources implement the JRDataSource interface. UR provides many ready-to-use implementations ofdata sources to wrap generic data structures, like arrays or collections of JavaBeans, result sets, table models, CSV and XMLfiles, and so on. In this chapter I will present some of these data sources, and you will see how easy it is to create a custom datasource to fit any possible need. Finally, you will see how to define a custom query language and a custom query executor, aswell as how to use them.iReport provides support for all these things: you can define JDBC (Java Database Connectivity) connections to execute SQLqueries, set up Hibernate connections using Spring, and test your own JRDataSource or your custom query language.This chapter has the following sections:• How a UR Data Source Works• Understanding Data Sources and Connections in iReport• Creating and Using JDBC Connections• Working with Your JDBC Connection• Understanding the JRDataSource Interface• Data Source Types• Importing and Exporting Data Sources11.1 How a UR Data Source WorksUR is a records-based engine; to print a report, you have to provide a set of records. When the report runs,UR will iterate on this record set, creating and filling the bands according to the report definition. Bands, groups,variables—their elaboration is strictly tied to the record set used to fill the report. This is why UR defines only onequery per report. However, multiple queries/data sources can be used when inserting subreports or defining subdatasets. Each171
- Page 119 and 120: Bands and GroupsFigure 7-14 shows t
- Page 121 and 122: 7.3 Other Group OptionsBands and Gr
- Page 123 and 124: Fonts and StylesCHAPTER 8FONTS AND
- Page 125 and 126: Fonts and StylesThe list of availab
- Page 127 and 128: Fonts and StylesFigure 8-5Font Exte
- Page 129 and 130: Fonts and StylesFigure 8-7Font Exte
- Page 131 and 132: Fonts and StylesFigure 8-10The new
- Page 133 and 134: Fonts and StylesTo apply a style to
- Page 135 and 136: Fonts and StylesFigure 8-17The outl
- Page 137 and 138: TemplatesCHAPTER 9TEMPLATESOne of t
- Page 139 and 140: TemplatesFigure 9-2Columnar reportA
- Page 141 and 142: TemplatesFigure 9-4Group by step in
- Page 143 and 144: TemplatesIf a static text element i
- Page 145 and 146: TemplatesFigure 9-8Your custom temp
- Page 147 and 148: TemplatesFigure 9-10New template in
- Page 149 and 150: TemplatesFigure 9-12Preview of repo
- Page 151 and 152: SubreportsCHAPTER 10 SUBREPORTSSubr
- Page 153 and 154: SubreportsFigure 10-3Subreport elem
- Page 155 and 156: SubreportsFigure 10-4Subreport Para
- Page 157 and 158: SubreportsFigure 10-7Just a list of
- Page 159 and 160: SubreportsFigure 10-11 Subreport Wi
- Page 161 and 162: SubreportsFigure 10-14 The final re
- Page 163 and 164: Subreports3. Click the Add button t
- Page 165 and 166: Subreports10.4 Using the Subreport
- Page 167 and 168: SubreportsFigure 10-21 Subreport co
- Page 169: SubreportsFigure 10-23 Setting Subr
- Page 173 and 174: Data Sources and Query Executers•
- Page 175 and 176: Data Sources and Query ExecutersFig
- Page 177 and 178: Data Sources and Query ExecutersFig
- Page 179 and 180: Data Sources and Query ExecutersFig
- Page 181 and 182: Data Sources and Query ExecutersFig
- Page 183 and 184: Data Sources and Query ExecutersFig
- Page 185 and 186: Data Sources and Query ExecutersFig
- Page 187 and 188: Data Sources and Query Executers•
- Page 189 and 190: Data Sources and Query ExecutersAft
- Page 191 and 192: Data Sources and Query ExecutersIns
- Page 193 and 194: Data Sources and Query Executerspub
- Page 195 and 196: Data Sources and Query ExecutersFig
- Page 197 and 198: Data Sources and Query ExecutersFig
- Page 199 and 200: Data Sources and Query Executersbe
- Page 201 and 202: Data Sources and Query ExecutersFig
- Page 203 and 204: Data Sources and Query ExecutersWhe
- Page 205 and 206: Data Sources and Query ExecutersCod
- Page 207 and 208: Data Sources and Query ExecutersPre
- Page 209 and 210: Data Sources and Query ExecutersFig
- Page 211 and 212: Data Sources and Query Executersspe
- Page 213 and 214: Data Sources and Query Executers•
- Page 215 and 216: Data Sources and Query Executersof
- Page 217 and 218: Data Sources and Query ExecutersThi
- Page 219 and 220: Data Sources and Query ExecutersCod
Data Sources and Query ExecutersCHAPTER 11 DATA SOURCES AND QUERY EXECUTERSThere are several ways that UR can provide data to fill a report. For example, you can put an SQL query directlyinside a report and provide a connection to a database against which to execute the query and read the resulting record set, oryou can use a more sophisticated custom technology to provide a table-like set of values.<strong>iReport</strong> provides direct support for a rich set of query languages, including SQL, HQL, EJBQL, and MDX, and supports otherlanguages like XPath (XML Path Language). Moreover, in <strong>iReport</strong>, you can use custom languages by registering plug-inengines called query executors to interpret and execute the report query.If you don’t want to use a query language, or you simply don’t want to put the query inside a report, you can use a URdata source. Basically, a JR data source is an object that iterates on a record set that is organized like a simpletable.All the data sources implement the JRDataSource interface. UR provides many ready-to-use implementations ofdata sources to wrap generic data structures, like arrays or collections of JavaBeans, result sets, table models, CSV and XMLfiles, and so on. In this chapter I will present some of these data sources, and you will see how easy it is to create a custom datasource to fit any possible need. Finally, you will see how to define a custom query language and a custom query executor, aswell as how to use them.<strong>iReport</strong> provides support for all these things: you can define JDBC (Java Database Connectivity) connections to execute SQLqueries, set up Hibernate connections using Spring, and test your own JRDataSource or your custom query language.This chapter has the following sections:• How a UR Data Source Works• Understanding Data Sources and Connections in <strong>iReport</strong>• Creating and Using JDBC Connections• Working with Your JDBC Connection• Understanding the JRDataSource Interface• Data Source Types• Importing and Exporting Data Sources11.1 How a UR Data Source WorksUR is a records-based engine; to print a report, you have to provide a set of records. When the report runs,UR will iterate on this record set, creating and filling the bands according to the report definition. Bands, groups,variables—their elaboration is strictly tied to the record set used to fill the report. This is why UR defines only onequery per report. However, multiple queries/data sources can be used when inserting subreports or defining subdatasets. Each171