java - jasper report with spring empty pdf -


i'm working on over week , i've used 2 examples no 1 working me. me find mistake in code?

connection conn = null;     try {         try {             class.forname("com.mysql.jdbc.driver");         } catch (classnotfoundexception e) {             system.out.println("please include classpath mysql driver located");             e.printstacktrace();         }         conn = drivermanager.getconnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");         if (conn != null)         {             system.out.println("database connected");         } else         {             system.out.println(" connection failed ");         }         //parameters map passed jasper         hashmap<string,object> hmparams=new hashmap<string,object>();         hmparams.put("dec_id", new integer(id));         inputstream paiementreportstream= getclass().getresourceasstream("jasper/paiement_db.jrxml");         jasperreport jasperreport= jaspercompilemanager.compilereport(paiementreportstream);         jrsaver.saveobject(jasperreport, "paiement_db.jasper");         jasperprint jasperprint = jasperfillmanager.fillreport(jasperreport, hmparams, conn);         jrpdfexporter exporter = new jrpdfexporter();          exporter.setexporterinput(new simpleexporterinput(jasperprint));         simpleoutputstreamexporteroutput out =new simpleoutputstreamexporteroutput("paiement_db.pdf");         exporter.setexporteroutput(out);          simplepdfreportconfiguration reportconfig= new simplepdfreportconfiguration();         reportconfig.setsizepagetocontent(true);         reportconfig.setforcelinebreakpolicy(false);         simplepdfexporterconfiguration exportconfig = new simplepdfexporterconfiguration();         exportconfig.setmetadataauthor("baeldung");         exportconfig.setencrypted(true);         exportconfig.setallowedpermissionshint("printing");         exporter.setconfiguration(reportconfig);         exporter.setconfiguration(exportconfig);         exporter.exportreport();      } catch (exception sqlexp) {         system.out.printf("exception::");         sqlexp.printstacktrace();     } {         try {             if (conn != null) {                 conn.close();                 conn = null;             }         } catch (sqlexception expsql) {             system.out.println("sqlexp::closing::" + expsql.tostring());         }      } 

i've got code example http://www.baeldung.com/spring-jasper , i've tried code of following example http://javaonlineguide.net/2015/05/spring-4-jasper-report-integration-example-with-mysql-database-in-eclipse.html

string reportfilename = "paiement_db";      connection conn = null;     try {         try {             class.forname("com.mysql.jdbc.driver");         } catch (classnotfoundexception e) {             system.out.println("please include classpath mysql driver located");             e.printstacktrace();         }         conn = drivermanager.getconnection("jdbc:mysql://127.0.0.1:3306/jwayma_tax2","student","student");         if (conn != null)         {             system.out.println("database connected");         } else         {             system.out.println(" connection failed ");         }         //parameters map passed jasper         hashmap<string,object> hmparams=new hashmap<string,object>();         hmparams.put("dec_id", new integer(id));         jasperreport jasperreport = getcompiledfile(reportfilename, request);         generatereportpdf(response, hmparams, jasperreport, conn);// pdf report      } catch (exception sqlexp) {         system.out.printf("exception::");         sqlexp.printstacktrace();     } {         try {             if (conn != null) {                 conn.close();                 conn = null;             }         } catch (sqlexception expsql) {             system.out.println("sqlexp::closing::" + expsql.tostring());         }      } 

this template.jrxml

<?xml version="1.0" encoding="utf-8"?> 

http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="blank_a4_1" pagewidth="595" pageheight="842" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20" uuid="31c3a6bf-74ad-4135-99dc-c0a601aa63e1">

outdated: i seems provide file string , jasper expect url. create file object , create url it.

inputstream paiementreportstream= getclass().getresourceasstream("jasper/paiement_db.jrxml"); 

the resource not found? check if paiementreportstream null.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -