prasanthi Posted September 30, 2008 Share Posted September 30, 2008 Hi, I want to pass paramere student ID to the Query in jasper report .how to pass Student ID String to jasper report.regardsprasanthi Link to comment Share on other sites More sharing options...
ethael Posted September 30, 2008 Share Posted September 30, 2008 sELECT * FROM students WHERE id LIKE '$P{STUDENT_ID}' Of course you need to have this parameter declared in report: You should replace java.lang.String for something else if necessary... And of course take care of proper set of the parameter value Link to comment Share on other sites More sharing options...
ethael Posted September 30, 2008 Share Posted September 30, 2008 <queryString><![CDATA[sELECT * FROM students WHERE id LIKE '$P{STUDENT_ID}']]></queryString>Of course you need to have this parameter declared in report:<parameter name="STUDENT_ID" isForPrompting="false" class="java.lang.String"></parameter>You should replace java.lang.String for something else if necessary...And of course take care of proper set of the parameter value Link to comment Share on other sites More sharing options...
prasanthi Posted September 30, 2008 Author Share Posted September 30, 2008 I want send String parameter ,Example StudID as bellowString StuID="MCA001";from Servlet(any java code) to jasper report.I do't know how to write the code to send to send this paramete to jasper report.you told the changes in jasper report for passing parameter right .But i need code for java also.Thank you Link to comment Share on other sites More sharing options...
dnvsrikanth Posted October 1, 2008 Share Posted October 1, 2008 hi prasanthi, Pass the parameters in the following way: Declare a Hashmap and put the parameters in the parameters in the map and pass the hashmap in the following way: Code:HashMap map = new HashMap();JasperPrint jasperPrint = null;Connection connection = null;map.put("p_StuID","MCA001"); jasperPrint = JasperFillManager.fillReport(ClarificationSummaryReport.jasper",map,connection); Link to comment Share on other sites More sharing options...
usuario13 Posted October 14, 2008 Share Posted October 14, 2008 I''ve got a servlet with this code:String user = request.getParameter("USER");HashMap map = new HashMap();map.put("nomUsuari",user); JasperPrint print = JasperFillManager.fillReport(report, map, conn);And a jrxml file with this: <queryString language="SQL"> <![CDATA[sELECT * FROM usuaris WHERE USER LIKE '$p{nomUsuari}']]> </queryString>And fields like this: <field name="USER" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field>But as a result, i get an empty PDF document and no errors. I've got another servlet with the same code, but with a null HashMap, and a query string like "select * from table" and it works fine. What's the problem? Thanks Link to comment Share on other sites More sharing options...
jmastajam Posted October 14, 2008 Share Posted October 14, 2008 You don't need to put single quotation mark (') around the parameter marker because it gets replace by the parameter value. Should be like this: sELECT * FROM usuaris WHERE USER LIKE $p{nomUsuari} HTH Link to comment Share on other sites More sharing options...
jmastajam Posted October 14, 2008 Share Posted October 14, 2008 SELECT * FROM usuaris WHERE USER LIKE $p{nomUsuari} Link to comment Share on other sites More sharing options...
usuario13 Posted October 15, 2008 Share Posted October 15, 2008 Thank you. I also missed this: <parameter name="nomUsuari" isForPrompting="false" class="java.lang.String"/> :) Link to comment Share on other sites More sharing options...
dnvsrikanth Posted October 15, 2008 Share Posted October 15, 2008 hi,<parameter name="STUDENT_ID" isForPrompting="false" class="java.lang.String"></parameter>In the above line set isForPrompting to true.... SELECT * FROM usuaris WHERE USER LIKE $p{nomUsuari}and in the query above use P instead of p in mentioning parameteras $P{nomUsuari} instead of $p{nomUsuari} DNV Srikanth Link to comment Share on other sites More sharing options...
emmadi Posted October 16, 2008 Share Posted October 16, 2008 Hi i am trying to generate report by passing the value from pdf.jsp i did all the things which u had discussed but i am getting a blank pdf as a result please can any body help meThanku Code: HashMap parameter = new HashMap(); parameter.put("gname",groupname);this code in pdf.jsp and<parameter name="gname" isForPrompting="true" class="java.lang.String"/> <queryString><![CDATA[select * from user_account where groupname=$P{gname}]]></queryString>in the jrxml file Link to comment Share on other sites More sharing options...
prasanthi Posted October 24, 2008 Author Share Posted October 24, 2008 hi, thanks to all of you.I used this solution, my problem solved Link to comment Share on other sites More sharing options...
harshchauhan Posted January 29, 2009 Share Posted January 29, 2009 hi,i'm a new bie to jasper reports after searching a lot on passing a parameter from java to query string in report, i could not make my report run as i intend to.i'm passing a parameter Map parameter= new HashMap(); parameter.put("vrno",vrno); // here vrno is the value that i'm fetching from the text field. // SHOW THE REPORT public void showReport(){ try{ // PREPARING DATABASE CONNECTION Connection con = jb.getConnection(); System.out.println("parameter in ireport = "+vrno+(String)parameter.get("vrno")); File file = new File(FULLPATH+reportName+".jrxml"); // File file = new File(FULLPATH+reportName+".jasper"); System.out.println("file.exists ="+file.exists()); InputStream is = new BufferedInputStream(new FileInputStream(file.getAbsolutePath())); JasperDesign jasperDesign=JRXmlLoader.load(file.getAbsolutePath()); JasperReport jr = JasperCompileManager.compileReport(jasperDesign); // FILL THE REPORT JPrint=JasperFillManager.fillReport(jr, parameter, con); // PRINT REPORT TO PDF FILE. if(TASK_PDF.equalsIgnoreCase(task)) { OutputStream output = new FileOutputStream(new File("d:/"+reportName+".pdf")); JasperExportManager.exportReportToPdfStream(JPrint, output); System.exit(0); } // VIEW THE REPORT JasperViewer.viewReport(JPrint); in my jrxml file the parameter element is<parameter name="vrno" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA[new String("PP08Y-00002")]]></defaultValueExpression> </parameter>and my query string isselect * from order_head WHERE ORDER_HEAD.VRNO='$P!{vrno}' ---------------------------------------------- 1when i'm using a hard coded vrno(PP08Y-00001) AT $P!{vrno}, the report runs finebut when i use the parameter string the message displays --- the document has no page...please help... Link to comment Share on other sites More sharing options...
kumar.pavan983 Posted April 5, 2016 Share Posted April 5, 2016 input control is working fine but when i run the report in the server directly it will come to provide input paramter but what i want is frist i want full data to be displyed and latter input control are to be displyed so that it will be easy for me how to do that help me Link to comment Share on other sites More sharing options...
edramu31 Posted May 11, 2016 Share Posted May 11, 2016 HelloI am new at jaspersoft and I am working on a Report that I can fill without problem from the ireport previewBut when I try to fill the same report from the following java.class //Conexión a base de datos Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); java.sql.Connection conexion = DriverManager.getConnection("jdbc:sqlserver://172.23.65.22:1433;databaseName=ET_GOLF_4X4_vC", "usr_hdbase_ali", "$M0n1t0r"); //Mapeo de parámetros para reporte Map parametros=new HashMap(); //parametros.put("UID_M", UID); parametros.put("UID_M","G40001J"); parametros.put("LOGO_VW",this.getClass().getResourceAsStream("/Imagenes_Reporte/Logo_VW_2000x2000.png")); parametros.put("LOGO_IAU",this.getClass().getResourceAsStream("/Imagenes_Reporte/Logo IAU_189x111.png")); //Compilación de reporte JasperReport jasperReport = JasperCompileManager.compileReport("C:\Users\Edgar Ramirez\Dropbox\ERM\Aprendizaje\JAVA\Proyectos NETBEANS\ReporteLigero\src\reporteligero\Reporte_Aprietes_Oficial_vA.jrxml"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parametros, conexion); The key paramater is parametros.put("UID_M","G40001J");I get the following issuenet.sf.jasperreports.engine.JRException: Error executing SQL statement for: null.at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:344)at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1129)at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:696)at net.sf.jasperreports.engine.fill.BaseReportFiller.setParameters(BaseReportFiller.java:437)at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:548)at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:396)at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:90)at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:863)at Reporteador_AG4X4.Aplicacion_Reporteo.btnGenerarReporteAprietesOficialActionPerformed(Aplicacion_Reporteo.java:1765) Can you help me please? Greetings!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now