Hi there!, i'm still working on it!... I have my report, and my subreport
both are succesfully compiled and shown using ireport, but when I compile my
masterReport the subreport isnt shown!...
I have a class, that compiles the reports too, but it is the same, i
followed a tutorial for doing this, but anyway the subreport isnt shown!!...
This is package reportcreator; my Class
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
/**
* <p>
* Ejemplo práctico de visualización de un reporte de JasperReports que
contiene
* un subreporte.
* </p>
* <p>
* Esta clase ha sido desarrollada para ilustrar el tutorial "JasperReports,
* iReport y Subreportes" escrito para la comunidaad de javaHispano.
* </p>
*
* @author Francesc Rosés i Albiol
*/
public class SubreportsSample {
public static void main(String[] args) {
// Cargamos el driver JDBC
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("MySQL JDBC Driver not found.");
System.exit(1);
}
// Obtenemos las URLs del reporte maestro y del subreporte
SubreportsSample t1 = new SubreportsSample();
URL urlMaestro =t1.getClass
().getResource("/Reportes/SASHtmlLand.jasper");
URL urlSubreporte =t1.getClass
().getResource("/Reportes/sas_reporteGastos_subreport0.jasper");
if (urlMaestro == null) {
System.out.println("No encuentro el archivo del
reporte maestro.");
System.exit(2);
}
if (urlSubreporte == null) {
System.out.println("No encuentro el archivo del
subreporte.");
System.exit(2);
}
// Cargamos el reporte maestro
JasperReport masterReport = null;
try {
masterReport = (JasperReport) JRLoader.loadObject
(urlMaestro);
} catch (JRException e) {
System.out
.println("Error cargando el reporte
maestro: " + e.getMessage());
System.exit(3);
}
// Cargamos el subreporte
JasperReport subReport = null;
try {
subReport = (JasperReport) JRLoader.loadObject
(urlSubreporte);
} catch (JRException e) {
System.out.println("Error cargando el subreporte: "
+ e.getMessage());
System.exit(3);
}
// Obtenemos una conexión con la base de datos
Connection con = null;
try {
con = DriverManager.getConnection
("jdbc:mysql://localhost/sascolombia","root","");
} catch (SQLException e) {
System.out.println("Error de conexión: " +
e.getMessage());
System.exit(4);
}
// Parámetros del reporte maestro
String param1="79000001";
String param2="2";
Map masterParams = new HashMap();
masterParams.put("param1", param1);
masterParams.put("param2", param2);
masterParams.put("id", param2);
masterParams.put("SUBREPORT", subReport);
// Parámetros del subreporte:
// Ninguno. El parámetro PERSONA_ID, se lo pasa
// el report maestro
// Llenamos el reporte maestro (y por ende el subreporte)
// y obtenemos un objeto JasperPrint que puede ser
// visualizado, impreso o exportado
JasperPrint masterPrint = null;
try {
masterPrint =
JasperFillManager.fillReport(masterReport,
masterParams,
con);
} catch (JRException e) {
System.out
.println("Error llenando el reporte
maestro: " + e.getMessage());
try {
con.close();
} catch (SQLException e1) {
}
System.exit(5);
}
// Visualizamos el reporte
try {
JasperViewer.viewReport(masterPrint, false);
} catch (Exception e) {
System.out.println("View report error: " +
e.getMessage());
}
// Cerramos la conexión con la base de datos
try {
con.close();
} catch (SQLException e) {
}
}
}
If you need more details just tell me and i will be submiting em soon!...
Greetings
George...
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
jasperreports-questions mailing list
jasperreports-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jasperreports-questions