Jump to content
Changes to the Jaspersoft community edition download ×

how to pass a query by parameter??


2004 IR Help

Recommended Posts

By: mab - maborou

how to pass a query by parameter??

2004-08-24 08:05

 

Hi!! I'd want to know how to pass a query by parameter. It's very important for me to know it cause I'm too late in my job!!!

 

thanks!!!!

 

 

 

 

By: cosjav - cosjav

RE: how to pass a query by parameter??

2004-08-24 17:34

Hi,

 

you need to set the report query as something like: $P!{myQuery} and then set this parameter at runtime with a string containing your query... (NOTE: you must remember to include the ! )

 

if you dont get what im on about let me know, i will elaborate...

 

cosjav

 

 

 

 

By: mab - maborou

RE: how to pass a query by parameter??

2004-08-25 00:28

I'm gonna try it!!! Thanks!!

 

 

 

 

By: mab - maborou

RE: how to pass a query by parameter??

2004-08-25 00:43

Hi cosjav!!!

 

I have just tried but it doesn't work, maybe I did it wrong?! Can you explain more or give me an example pleaz?!

 

thanks for all!!!!

 

 

 

 

By: mab - maborou

RE: how to pass a query by parameter??

2004-08-25 02:22

Re Hi cosjav!!!

 

I was wrong!! Now it works very well!!

 

Thanks for your help!!!!

 

 

 

 

By: cosjav - cosjav

RE: how to pass a query by parameter??

2004-08-25 16:53

no problem :)

 

glad it worked out :)

 

 

 

 

By: mir_shajahan - comp_shajahan

RE: how to pass a query by parameter??

2004-10-21 01:11

Hai...

I already tried that method... but its not working for me... just because once I edit my report query... the OK button is disabled. So I cannot save the changes....

 

Is there any other way to add in parameter?

 

Thank you...

 

<< aMir >>

 

 

 

 

By: djiska - djiska

RE: how to pass a query by parameter??

2004-10-21 15:07

Hi

 

My query is this:

 

SELECT ALUMNOS_P.DNI, ALUMNOS_P.NOMBRE, ALUMNOS_P.APELLIDO1,

ALUMNOS_P.APELLIDO2, CALIFICACIONES.CALIFICACION FROM ALUMNOS_P, ASIG_MATRI_P, CALIFICACIONES

WHERE ALUMNOS_P.EXPEDIENTE = ASIG_MATRI_P.EXPEDIENTE AND

ALUMNOS_P.CENTRO = ASIG_MATRI_P.CENTRO AND

ALUMNOS_P.SECCION = ASIG_MATRI_P.SECCION AND

ALUMNOS_P.PLAN = ASIG_MATRI_P.PLAN AND

ASIG_MATRI_P.NOTA14 = CALIFICACIONES.CODIGO AND

ASIG_MATRI_P.COD_ASIG = $P!{CODASIG} AND

ASIG_MATRI_P.SECCION LIKE '$P!{SECCION}' AND

ASIG_MATRI_P.CURSOACAD LIKE '$P!{CURSOACAD}' AND

ASIG_MATRI_P.PLAN = $P!{PLAN} AND

ASIG_MATRI_P.CENTRO = $P!{CENTRO}

ORDER BY ALUMNOS_P.APELLIDO1, ALUMNOS_P.APELLIDO2, ALUMNOS_P.NOMBRE

 

I create the parameters in the options report parameters:

- EXPEDIENTE is defined (type String)

- SECCION is defined (type String) in we defined by default new String('s')

- PLAN is defined (type integer) in we defined by default new Integer(3)

- CENTRO is defined (type integer) in we defined by default new Integer(212)

- CODASIG is defined (type integer) in we defined by default new Integer(211)

- CURSOACAD is defined (type String) in we defined by default new String('2003')

- CURSO is defined (type String) in we defined by default new String("")

- TITULACION is defined (type String) in we defined by default new String("")

 

for last I create the code java. I create a class InformesActas:

 

class InformesActas {

 

static final String PATH_INFORME = "C:/../Informes/";

 

public InformesActas(String pathXml) {

try {

dori.jasper.engine.design.JasperDesign jasperDesign = dori.jasper.engine.JasperManager.loadXmlDesign(PATH_INFORME + pathXml);

dori.jasper.engine.design.JRBshCompiler theCompiler = new dori.jasper.engine.design.JRBshCompiler();

dori.jasper.engine.JasperReport jasperReport = theCompiler.compileReport(jasperDesign);

 

Map parameters = new HashMap();

 

DBAsignatura asignatura = new DBAsignatura(MiArbol.codigoAsig, MiArbol.centro, MiArbol.seccion, MiArbol.plan, MiArbol.cursoAcademico);

Integer i = new Integer(MiArbol.codigoAsig);

parameters.put("CURSO",asignatura.curso);

parameters.put("TITULACION", asignatura.nombreAsig);

parameters.put("CODASIG", i);

parameters.put("SECCION", MiArbol.seccion);

parameters.put("CURSOACAD", MiArbol.cursoAcademico);

parameters.put("CENTRO", new Integer(MiArbol.centro));

parameters.put("PLAN", new Integer(MiArbol.plan));

/*System.out.println("Codigo Asig: " + i.toString() + "n" +

"Seccion: " + MiArbol.seccion + "n" +

"Plan: " + MiArbol.plan + "n" +

"Curso Acad: " + MiArbol.cursoAcademico + "n" +

"Centro: " + MiArbol.centro);*/

Connection con=null;

 

try {

BDConexion conexion = new BDConexion();

con = conexion.AbrirConexion();

}

catch(Exception e){

System.out.println("Exception in test.jsp "+ e);

}

 

dori.jasper.engine.JasperPrint jasperPrint = dori.jasper.engine.JasperFillManager.fillReport(jasperReport,parameters,con);

dori.jasper.engine.JasperManager.printReportToPdfFile(jasperPrint,"ReportA.pdf");

dori.jasper.view.JasperViewer.viewReport(jasperPrint,false);

Marco1.JLABELBARRADEESTADO.setText("Operació®º" + "Preparado para imprimir");

}

catch(Exception e){ System.out.println("There is exception here"+ e);

}

}

}

 

this works perfectly. I test it so much.

 

I hope help you. greets.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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