I’ll show you how to build a Jasperreports report from scratch, since you don’t know exactly what the problem is.
In Jasperreport Studio 5.6.0:
First thing is to set the Data Adapter by clicking on "Data Adapters > Create New Data Adapter"
In this example I will use the Database JDBC Connection, but then the developer chooses and populates the data. You must test the connection and see if it returns "Sucessful".
Next you go to the Dataset and Query editor dialog:
Select your Data Adapter in the upper left corner and paste your query in the right side. See if all fields appear in the menu below (Usually it is automatic). This will be in the "Fields tab".
Returning to the design of your report (figure 2), in the "Detail" section, the fields that will be received from DB should be placed in a Textfield and its expression should have the following format: $F{nomedocampo}
(Figure 4 - Right side), being the tag $P{nomedocampo}
for parameters. The parameters must be placed by the developer before the report generation (including the preview). To create a new parameter go to the "Outline (lower left field) > Parameters > Create Parameter" menu. (Figure 4 - Left side)
By clicking "Preview" to check that everything is correctly displayed your file . Jasper will be generated automatically.
In the Java code:
// Gerando um relatório com parâmetros
HashMap params = new HashMap<>();
params.put("nomeParametro", inputDoParametro);
URL arquivo = getClass().getResource("/com/seuprograma/seupackage/relatorio.jasper");
JasperReport jreport = (JasperReport) JRLoader.loadObject(arquivo);
JasperPrint jprint = JasperFillManager.fillReport(jreport, params, JDBCconnection);
// Gerando o pdf
JasperExportManager.exportReportToPdfFile(jprint, file.getPath());
Report without parameters:
URL arquivo = getClass().getResource("/com/seuprograma/seupackage/relatorio.jasper");
JasperReport jreport = (JasperReport) JRLoader.loadObject(arquivo);
JasperPrint jprint = JasperFillManager.fillReport(jreport, null, JDBCconnection);
// Gerando o pdf
JasperExportManager.exportReportToPdfFile(jprint, file.getPath());
This procedure was tested with an SQLITE database, using JDBC sqlite-jdbc-3.19. 3, java 8 and jasperstudio 5.6.0/ireports 5.6.0. Libs used:
commons-beanutils-1.9.3.jar
commons-collections-3.2.2.jar
commons-digester-2.1.jar
commons-javaflow-20160505.jar
commons-logging-1.1.1.jar
itext-2.1.7.js6.jar
jasperreports-6.4.1.jar
Before answering clarify a few things: what do you want in Details comes from a query? What is your datasource?
– Gustavo Fragoso
I tried it with querys (and when I tested it in the preview of Jasperstudio it showed right) and tried to put a Static Text (which in the preview also worked) but when I will generate the report, the PDF file displays everything but the contents of the Tails tab
– R.Santos