Jump to content
Changes to the Jaspersoft community edition download ×

how to pass parameters to jasper report


prasanthi

Recommended Posts

  • Replies 14
  • Created
  • Last Reply

Top Posters In This Topic

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

<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

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

 

 

Link to comment
Share on other sites

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

  • 2 weeks later...

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

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

Link to comment
Share on other sites

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 
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

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...

 

 

 

Link to comment
Share on other sites

  • 7 years later...

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

  • 1 month later...

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!!
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...