how to pass parameters to jasper report

0

Hi,

   I want to pass paramere student ID to the Query in jasper report .how to pass Student ID String to jasper report.

regards

prasanthi

prasanthi's picture
Joined: Jun 23 2008 - 4:59pm
Last seen: 10 years 9 months ago

14 Answers:

-4
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
ethael's picture
7
Joined: Jun 11 2008 - 12:45am
Last seen: 10 years 9 months ago
0

<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
 

ethael's picture
7
Joined: Jun 11 2008 - 12:45am
Last seen: 10 years 9 months ago
2

I want send String parameter ,Example StudID as bellow

String 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

 

 

prasanthi's picture
Joined: Jun 23 2008 - 4:59pm
Last seen: 10 years 9 months ago
0

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);</td></tr></tbody></table>
dnvsrikanth's picture
Joined: Jul 22 2007 - 1:29pm
Last seen: 4 months 6 days ago
0

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

usuario13's picture
Joined: Oct 14 2008 - 3:33am
Last seen: 10 years 5 months ago
0
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: HTH
nnguyen's picture
50
Joined: Aug 20 2008 - 12:05pm
Last seen: 10 years 7 months ago
0

SELECT * FROM usuaris WHERE USER LIKE $p{nomUsuari}

 

nnguyen's picture
50
Joined: Aug 20 2008 - 12:05pm
Last seen: 10 years 7 months ago
0

Thank you.

 

I also missed this: <parameter name="nomUsuari" isForPrompting="false" class="java.lang.String"/>

 

:)

usuario13's picture
Joined: Oct 14 2008 - 3:33am
Last seen: 10 years 5 months ago
0

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 parameter

as $P{nomUsuari} instead of $p{nomUsuari}

 

DNV Srikanth

dnvsrikanth's picture
Joined: Jul 22 2007 - 1:29pm
Last seen: 4 months 6 days ago
0

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 me

Thanku 

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 </td></tr></tbody></table>
emmadi's picture
7
Joined: Oct 15 2008 - 9:41pm
Last seen: 10 years 5 months ago
1
hi, thanks to all of you.I used this solution, my problem solved
prasanthi's picture
Joined: Jun 23 2008 - 4:59pm
Last seen: 10 years 9 months ago
0

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 is

select * from order_head WHERE ORDER_HEAD.VRNO='$P!{vrno}' ---------------------------------------------- 1
when i'm using a hard coded vrno(PP08Y-00001) AT $P!{vrno}, the report runs fine

but when i use the parameter string the message displays --- the document has no page...

please help...

 

 

 

harshchauhan's picture
Joined: Jan 28 2009 - 8:59pm
Last seen: 10 years 1 month ago
0

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 

kumar.pavan983's picture
Joined: Feb 15 2016 - 2:33am
Last seen: 2 years 11 months ago
0

Hello

I am new at jaspersoft and I am working on a Report that I can fill without problem from the ireport preview

But 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 issue

net.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!!
edramu31's picture
Joined: Mar 5 2016 - 11:50am
Last seen: 2 years 10 months ago
Feedback
randomness