Es la primera vez que utilizo IReport, me base en un ejemplo que encontre en internet, pero al ejecutarlo me marca el siguiente error:
Los clases que utilizo son las siguientes
Capacitacion.java
Conexion.java
Reportes.java
No se si alguien pudiera ayudarme
Código [Seleccionar]
0 [main] DEBUG net.sf.jasperreports.engine.xml.JRXmlDigesterFactory - Using SAX parser factory class net.sf.jasperreports.engine.xml.JRReportSaxParserFactory
7 [main] DEBUG net.sf.jasperreports.engine.xml.BaseSaxParserFactory - Instantiated SAX parser factory of type com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
22 [main] DEBUG net.sf.jasperreports.extensions.ExtensionsEnvironment - Instantiating extensions registry class net.sf.jasperreports.extensions.DefaultExtensionsRegistry
24 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Loading registries for cache key sun.misc.Launcher$AppClassLoader@709db0ad
24 [main] DEBUG net.sf.jasperreports.engine.util.JRLoader - Found resource jasperreports_extension.properties at jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-5.5.0.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@709db0ad
25 [main] DEBUG net.sf.jasperreports.engine.util.JRLoader - Found resource jasperreports_extension.properties at jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-fonts-5.5.0.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@709db0ad
25 [main] DEBUG net.sf.jasperreports.engine.util.JRLoader - Found resource jasperreports_extension.properties at jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-javaflow-5.5.0.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@709db0ad
25 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Loading JasperReports extension properties resource jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-5.5.0.jar!/jasperreports_extension.properties
28 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.headertoolbar.HeaderToolbarParameterContributorExtensionFactory for property net.sf.jasperreports.extension.registry.factory.header.toolbar.parameter.contributor
28 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for header.toolbar.parameter.contributor using factory class net.sf.jasperreports.components.headertoolbar.HeaderToolbarParameterContributorExtensionFactory
31 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.types.date.DateRangeQueryClauseExtensions for property net.sf.jasperreports.extension.registry.factory.date.range.clause.functions
31 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for date.range.clause.functions using factory class net.sf.jasperreports.types.date.DateRangeQueryClauseExtensions
37 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.repo.DefaultRepositoryExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.repository
37 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for repository using factory class net.sf.jasperreports.repo.DefaultRepositoryExtensionsRegistryFactory
38 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.ContentTypeMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.content.type.mapping
38 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for content.type.mapping using factory class net.sf.jasperreports.web.util.ContentTypeMappingExtensionsRegistryFactory
40 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.simple.font.families
40 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for simple.font.families using factory class net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
41 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.data.DefaultDataAdapterServiceExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.data.adapter.services
41 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for data.adapter.services using factory class net.sf.jasperreports.data.DefaultDataAdapterServiceExtensionsRegistryFactory
43 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory for property net.sf.jasperreports.extension.registry.factory.jive.web.resource.handlers
43 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for jive.web.resource.handlers using factory class net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory
49 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.util.CastorMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.castor.mapping
49 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for castor.mapping using factory class net.sf.jasperreports.util.CastorMappingExtensionsRegistryFactory
50 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.export.MatcherExportFilterMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.matcher.exporter.filter.mapping
50 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for matcher.exporter.filter.mapping using factory class net.sf.jasperreports.engine.export.MatcherExportFilterMappingExtensionsRegistryFactory
51 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.governor
51 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for governor using factory class net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory
53 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.RequirejsModuleMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.requirejs.module.mapping
53 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for requirejs.module.mapping using factory class net.sf.jasperreports.web.util.RequirejsModuleMappingExtensionsRegistryFactory
54 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.query.SQLQueryClauseFunctionsExtensions for property net.sf.jasperreports.extension.registry.factory.sql.clause.functions
54 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for sql.clause.functions using factory class net.sf.jasperreports.engine.query.SQLQueryClauseFunctionsExtensions
59 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.style.PropertyStyleProviderExtensionFactory for property net.sf.jasperreports.extension.registry.factory.property.style.provider
60 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for property.style.provider using factory class net.sf.jasperreports.engine.style.PropertyStyleProviderExtensionFactory
61 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.JacksonMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.jackson.mapping
61 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for jackson.mapping using factory class net.sf.jasperreports.web.util.JacksonMappingExtensionsRegistryFactory
62 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.default
62 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for default using factory class net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory
65 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.components
65 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for components using factory class net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory
92 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.headertoolbar.HeaderToolbarConditionalStyleProviderExtensionFactory for property net.sf.jasperreports.extension.registry.factory.header.toolbar.style.provider
92 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for header.toolbar.style.provider using factory class net.sf.jasperreports.components.headertoolbar.HeaderToolbarConditionalStyleProviderExtensionFactory
93 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Loading JasperReports extension properties resource jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-fonts-5.5.0.jar!/jasperreports_extension.properties
93 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.simple.font.families
93 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for simple.font.families using factory class net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
93 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Loading JasperReports extension properties resource jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-javaflow-5.5.0.jar!/jasperreports_extension.properties
94 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.headertoolbar.HeaderToolbarParameterContributorExtensionFactory for property net.sf.jasperreports.extension.registry.factory.header.toolbar.parameter.contributor
94 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for header.toolbar.parameter.contributor using factory class net.sf.jasperreports.components.headertoolbar.HeaderToolbarParameterContributorExtensionFactory
94 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.types.date.DateRangeQueryClauseExtensions for property net.sf.jasperreports.extension.registry.factory.date.range.clause.functions
94 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for date.range.clause.functions using factory class net.sf.jasperreports.types.date.DateRangeQueryClauseExtensions
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.repo.DefaultRepositoryExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.repository
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for repository using factory class net.sf.jasperreports.repo.DefaultRepositoryExtensionsRegistryFactory
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.ContentTypeMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.content.type.mapping
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for content.type.mapping using factory class net.sf.jasperreports.web.util.ContentTypeMappingExtensionsRegistryFactory
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.simple.font.families
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for simple.font.families using factory class net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.data.DefaultDataAdapterServiceExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.data.adapter.services
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for data.adapter.services using factory class net.sf.jasperreports.data.DefaultDataAdapterServiceExtensionsRegistryFactory
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory for property net.sf.jasperreports.extension.registry.factory.jive.web.resource.handlers
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for jive.web.resource.handlers using factory class net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistryFactory
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.util.CastorMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.castor.mapping
95 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for castor.mapping using factory class net.sf.jasperreports.util.CastorMappingExtensionsRegistryFactory
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.export.MatcherExportFilterMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.matcher.exporter.filter.mapping
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for matcher.exporter.filter.mapping using factory class net.sf.jasperreports.engine.export.MatcherExportFilterMappingExtensionsRegistryFactory
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.governor
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for governor using factory class net.sf.jasperreports.governors.GovernorExtensionsRegistryFactory
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.RequirejsModuleMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.requirejs.module.mapping
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for requirejs.module.mapping using factory class net.sf.jasperreports.web.util.RequirejsModuleMappingExtensionsRegistryFactory
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.query.SQLQueryClauseFunctionsExtensions for property net.sf.jasperreports.extension.registry.factory.sql.clause.functions
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for sql.clause.functions using factory class net.sf.jasperreports.engine.query.SQLQueryClauseFunctionsExtensions
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.engine.style.PropertyStyleProviderExtensionFactory for property net.sf.jasperreports.extension.registry.factory.property.style.provider
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for property.style.provider using factory class net.sf.jasperreports.engine.style.PropertyStyleProviderExtensionFactory
96 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.web.util.JacksonMappingExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.jackson.mapping
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for jackson.mapping using factory class net.sf.jasperreports.web.util.JacksonMappingExtensionsRegistryFactory
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.default
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for default using factory class net.sf.jasperreports.extensions.DefaultExtensionsRegistryFactory
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.components
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for components using factory class net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating registry of type net.sf.jasperreports.components.headertoolbar.HeaderToolbarConditionalStyleProviderExtensionFactory for property net.sf.jasperreports.extension.registry.factory.header.toolbar.style.provider
97 [main] DEBUG net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Instantiating extensions registry for header.toolbar.style.provider using factory class net.sf.jasperreports.components.headertoolbar.HeaderToolbarConditionalStyleProviderExtensionFactory
99 [main] WARN net.sf.jasperreports.engine.component.ComponentsEnvironment - Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
99 [main] DEBUG net.sf.jasperreports.engine.xml.JRReportSaxParserFactory - Adding components schema at jar:file:/C:/JasperReports/jars/jasperreports-5.5.0/dist/jasperreports-5.5.0.jar!/net/sf/jasperreports/components/components.xsd
100 [main] DEBUG net.sf.jasperreports.engine.xml.BaseSaxParserFactory - Instantiating grammar pool of type com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl for cache key sun.misc.Launcher$AppClassLoader@709db0ad
107 [main] WARN net.sf.jasperreports.engine.component.ComponentsEnvironment - Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
210 [main] WARN net.sf.jasperreports.engine.component.ComponentsEnvironment - Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
net.sf.jasperreports.engine.JRException: java.net.MalformedURLException
Los clases que utilizo son las siguientes
Capacitacion.java
Código [Seleccionar]
package capacitacion;
import java.sql.SQLException;
import java.util.HashMap;
import utilidades.Conexion;
import utilidades.Reportes;
import org.apache.log4j.BasicConfigurator;
public class Capacitacion {
public static void main(String[] args) throws SQLException {
BasicConfigurator.configure();
// Creamos un objeto de la clase conexion
Reportes reporte= new Reportes();
try {
// llamamos al metodo get conection que nos devuelve un Objeto connection
HashMap<String, Object> mp= new HashMap<String, Object>();
// Lo exporta a pdf y lo muestra en la pantalla
Conexion.getInstancia().conectar();
reporte.jasperReport("D:/reportes.pdf",
Capacitacion.class.getResourceAsStream("C:/JasperReports/report3.jrxml")
, mp,
Conexion.getInstancia().getConexion());
Conexion.getInstancia().desconectar();
// Lamamos el metodo para conectarnos a la base de datos
Conexion.getInstancia().conectar();
// Llamamos el metodo que exporta a excel y lo guar en el pc en mi caso en E
reporte.reporteExcelImpresion(
Capacitacion.class.getResourceAsStream("C:/JasperReports/report3.jrxml")
,"D:/reportes.xls"
,mp,
Conexion.getInstancia().getConexion());
// Soltamos la conexion
Conexion.getInstancia().desconectar();
} catch (Exception ex) {
System.out.print(ex.toString());
}finally{
try {
Conexion.getInstancia().desconectar();
} catch (Exception e) {
System.out.print(e.toString());
}
}
}
}
Conexion.java
Código [Seleccionar]
package utilidades;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Conexion {
private Connection conexion; // Abstrae una conexion a la base de datos
private String usuario = "usuario"; // usuario con permisos para conectarse a Base de datos
private String password = "password"; // contraseña del usuario que se puede conectar a la base de datos
private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Clase del Driver de jConnector
private String beseDatos="jdbc:sqlserver://192.168.5.13\\aea;databaseName=dbMateriales";//cadena de conexión
private static Conexion instancia;
/** Crea a new instancia de Conexion */
public static Conexion getInstancia (){
if(Conexion.instancia==null){
Conexion.instancia=new Conexion();
}
return instancia;
}
/** Metodo que se encarga de conectar a la base de datos*/
public void conectar()throws Exception {
//si la conecion es null nos conectamos
if(this.getConexion()!=null){
return;
}
else if(this.getConexion() == null){
try {
Class.forName(this.getDriver()) ; // obtine una istancia de la clase Diver
// establece la conexion con el Diver jconector y este a su vez con la base de datos
this.setConexion(DriverManager.getConnection(this.getBeseDatos(), this.getUsuario(), this.getPassword()));
} catch (SQLException ex) {
System.out.print(ex.toString());
}
}
}
/** desconecta de la base de datos */
public void desconectar()throws Exception{
if(this.getConexion()==null)
this.setConexion(null);
}
public Conexion() {
}
/*Metodos getter y setter*/
public Connection getConexion() {
return conexion;
}
public void setConexion(Connection conexion) {
this.conexion = conexion;
}
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getBeseDatos() {
return beseDatos;
}
public void setBeseDatos(String beseDatos) {
this.beseDatos = beseDatos;
}
}
Reportes.java
Código [Seleccionar]
package utilidades;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.util.Locale;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRPdfExporterParameter;
import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.util.JRSaver;
import net.sf.jasperreports.view.JasperViewer;
public class Reportes implements Serializable{
private JasperReport reporte; private JasperPrint print;
//exportar reporte a axcel
public void reporteExcelImpresion(InputStream rutaJrxml,String rutaArchivoXLS,Map<String, Object> parametros,Connection conexion) throws JRException, FileNotFoundException{
this.reporte=JasperCompileManager.compileReport(rutaJrxml);
//luego ponemos los parametros que necesitamos:
print = JasperFillManager.fillReport(this.reporte, parametros, conexion);
JRXlsExporter exportador = new JRXlsExporter();
exportador.setParameter(JRExporterParameter.JASPER_PRINT,print);
exportador.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,rutaArchivoXLS);
exportador.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS,true);
exportador.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, false);
exportador.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_CELL_BORDER,false);
exportador.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,true);
exportador.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE ,true);
exportador.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED,true);
exportador.exportReport();
}
//metodo para generar el reporte en pdf si que se puedan copiar las imagenes ni el texto
public boolean jasperReport(String ruta, InputStream dataSourceName, Map<String, Object> params,Connection conn) throws ClassNotFoundException, JRException {
this.reporte=JasperCompileManager.compileReport(dataSourceName);
this.print = JasperFillManager.fillReport(this.reporte, params, conn);
if(this.print.getPages().isEmpty())
{
return false;
}
//int permisos =PdfWriter.ALLOW_PRINTING;
//Esta clase es la encargada de exportar el archivo a pdf
final JRExporter jtrtf= new JRPdfExporter();
jtrtf.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
jtrtf.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
//jtrtf.setParameter(JRPdfExporterParameter.PERMISSIONS, permisos);
jtrtf.setParameter(JRExporterParameter.JASPER_PRINT, this.print);
//Gurdamos una copia en el computador Ejemplo c:/reportes.jrprint
JRSaver.saveObject(this.print,ruta+".jrprint");
//Gurdamos una copia en el computador Ejemplo c:/reportes.pdf
jtrtf.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, ruta+".pdf");
//este metodo exporta a los diferentes formatos en este caso pdf
jtrtf.exportReport();
//Metodo que se encarga de mostrar el reporte en la pantalla
JasperViewer.viewReport(this.print,false,Locale.getDefault());
return true;
}
}
No se si alguien pudiera ayudarme