[RESOLVIDO] - Parametro com iReport

7 respostas
devvdevv.interior

Olá Pessoal, tudo bem??

A questão é a seguinte, no meu sql onde vou buscar as informações ela sem parametros ficaria da seguinte maneira.

select l.logendereco,ent.entnome,b.bennumlog, b.bencodigo, b.`BENNOMERESP`, s.`SETNOMEPREF`, s.`SETSETOR`, s.`SETCIDADE`, s.`SETENDERECO`,s.`SETEMAIL`,s.`SETUF`, s.`SETTEL`, s.`SETNOMEPREF` AS nomepref, s.`SETSETOR` AS setor, s.`SETCIDADE` AS cidade, s.`SETENDERECO` AS endereco, s.`SETEMAIL` AS email, s.`SETUF` AS uf, s.`SETTEL` AS telefone from logradouro l,setor s,beneficiario b, entidadesocial ent ,entidade_histentidade e WHERE b.bencodigo = e.hisentbencodigo and BENPROVIVALEITE = 'SIM' and s.setcodigo = 1 and b.BENLOGCODIGO = l.logcodigo and e.hisententcodigo = ent.entcodigo and ent.entcodigo =3 and e.hisentdtaini = '2011/10/11' and e.hisentdtasai is null;

desta forma, ele me tras resultados.

Agora caso eu for utilizar parametros exemplo:
no caso vou substituir BENPROVIVALEITE por meu parametro que é

$P{param1}

A questão é que quando vou executar meu relatorio, passo como parametro o BENPROVIVALEITE
e ele simplesmente diz que o documento não possui paginas…

Alguem sabe oq posso estar fazendo de errado?
pois passo o parametro igual apenas pra fazer o teste e ele nao me retorna, agora se eu deixar fixo ele me retorna…

OMG, I’m confused
desde já Obrigado.

7 Respostas

drsmachado

Por que BENPROVIVALEITE é uma coluna. Você só consegue passar como parâmetros valores, não colunas. É como o PreparedStatement do java, ele não aceita que você faça

String query = "SELECT * from tabela where ? = 'sim'";
ps.setString(1, 'COLUNA');

Manja?

otaviojava

você tem que passar o nome do parâmetro igual ao que está no relatório.
dá uma olhada acredito que vai ajudar.

http://javafree.uol.com.br/artigo/3154/Tutorial-de-IREPORT.html

devvdevv.interior

drsmachado:
Por que BENPROVIVALEITE é uma coluna. Você só consegue passar como parâmetros valores, não colunas. É como o PreparedStatement do java, ele não aceita que você faça

String query = "SELECT * from tabela where ? = 'sim'";
ps.setString(1, 'COLUNA');

Manja?

correto! entendo mas vejamos, eu tenho um combo que carrega em qual programa do governo o cliente quer fazer a busca das informações no relatorio sendo que cada programa é uma coluna na tabela, e tambem nao sei qual ele irá escolher por isso tenho que passar o parametro mas como posso passar? levando em consideração que é uma coluna da minha tabela?

obrigado desde já

drsmachado

tiago.sinatra:
correto! entendo mas vejamos, eu tenho um combo que carrega em qual programa do governo o cliente quer fazer buscar as informações no relatorio sendo que cada programa é uma coluna na tabela, e tambem nao sei qual ele irá escolher por isso tenho que passar o parametro mas como posso passar? levando em consideração que é uma coluna da minha tabela?
obrigado desde já

Não entendo teu português sem pontuação.
Porém, sei que relatórios jasper não permitem que você passe o nome das colunas como parâmetro, como disse anteriormente.

Até mesmo se você passar a query inteira como parâmetro, não será executada de forma adequada.

devvdevv.interior

Ok, obrigado.

devvdevv.interior

Segue a maneira, como resolvi este problema.

select l.logendereco,ent.entnome,b.bennumlog, b.bencodigo, b.`BENNOMERESP`, s.`SETNOMEPREF`, s.`SETSETOR`, s.`SETCIDADE`,
s.`SETENDERECO`,s.`SETEMAIL`,s.`SETUF`, s.`SETTEL`,
s.`SETNOMEPREF` AS nomepref,
s.`SETSETOR` AS setor,
s.`SETCIDADE` AS cidade,
s.`SETENDERECO` AS endereco,
s.`SETEMAIL` AS email,
s.`SETUF` AS uf,
s.`SETTEL` AS telefone
from logradouro l,setor s,beneficiario b, entidadesocial ent ,entidade_histentidade e 
WHERE b.bencodigo = e.hisentbencodigo
and BENPRORENDACIDADA = 'SIM' and $P{para1} = 'BENPRORENDACIDADA' OR
BENPROACAOJOVEM = 'SIM' and $P{para1} = 'BENPROACAOJOVEM' OR
BENPROMELHDEORIDA = 'SIM' and $P{para1} = 'BENPROMELHDEORIDA' OR
BENPROBOLSAFAMILIA = 'SIM' and $P{para1} = 'BENPROBOLSAFAMILIA' OR
BENPROVIVALEITE = 'SIM' and $P{para1} = 'BENPROVIVALEITE' OR
BENPROVIVALEITEIDOSO = 'SIM' and $P{para1} = 'BENPROVIVALEITEIDOSO' OR
BENPROPETI = 'SIM' and $P{para1} = 'BENPROPETI' OR
BENPROPROGER = 'SIM' and $P{para1} = 'BENPROPROGER' OR
BENPROLOAS = 'SIM' and $P{para1} = 'BENPROLOAS' OR
BENPROLOASDEF = 'SIM' and $P{para1} = 'BENPROLOASDEF' OR
BENPROPRONAF = 'SIM' and $P{para1} = 'BENPROPRONAF' OR
BENPROGPAIF = 'SIM' and $P{para1} = 'BENPROGPAIF' OR
BENPROPREVIDENCIA = 'SIM' and $P{para1} = 'BENPROPREVIDENCIA' OR
BENPROPROJOVEM = 'SIM' and $P{para1} = 'BENPROPROJOVEM' OR
BENPROPROJOVEMURB = 'SIM' and $P{para1} = 'BENPROPROJOVEMURB' OR
BENPROPROJOVEMCAMP = 'SIM' and $P{para1} = 'BENPROPROJOVEMCAMP' OR
BENPROPROJOVEMTRAB = 'SIM' and $P{para1} = 'BENPROPROJOVEMTRAB' OR
BENPROMELHORIASANITARIA = 'SIM' and $P{para1} = 'BENPROMELHORIASANITARIA' OR
BENPROHABINTSOC = 'SIM' and $P{para1} = 'BENPROHABINTSOC' OR
BENPROUPA = 'SIM' and $P{para1} = 'BENPROUPA' OR
BENPROHABBRAS = 'SIM' and $P{para1} = 'BENPROHABBRAS' OR
BENPROPROMORAD = 'SIM' and $P{para1} = 'BENPROPROMORAD' OR
BENPROMINCASMINVID = 'SIM' and $P{para1} = 'BENPROMINCASMINVID' OR
BENPROOPRCOLET = 'SIM' and $P{para1} = 'BENPROOPRCOLET' OR
BENPROPROMUNICIP = 'SIM' and $P{para1} = 'BENPROPROMUNICIP'
and s.setcodigo = 1 and b.BENLOGCODIGO = l.logcodigo
and e.hisententcodigo = ent.entcodigo and ent.entcodigo =3
and e.hisentdtaini = '2011/10/11' and e.hisentdtasai is null;
drsmachado

tiago.sinatra:
Segue a maneira, como resolvi este problema.

select l.logendereco,ent.entnome,b.bennumlog, b.bencodigo, b.`BENNOMERESP`, s.`SETNOMEPREF`, s.`SETSETOR`, s.`SETCIDADE`, s.`SETENDERECO`,s.`SETEMAIL`,s.`SETUF`, s.`SETTEL`, s.`SETNOMEPREF` AS nomepref, s.`SETSETOR` AS setor, s.`SETCIDADE` AS cidade, s.`SETENDERECO` AS endereco, s.`SETEMAIL` AS email, s.`SETUF` AS uf, s.`SETTEL` AS telefone from logradouro l,setor s,beneficiario b, entidadesocial ent ,entidade_histentidade e WHERE b.bencodigo = e.hisentbencodigo and BENPRORENDACIDADA = 'SIM' and $P{para1} = 'BENPRORENDACIDADA' OR BENPROACAOJOVEM = 'SIM' and $P{para1} = 'BENPROACAOJOVEM' OR BENPROMELHDEORIDA = 'SIM' and $P{para1} = 'BENPROMELHDEORIDA' OR BENPROBOLSAFAMILIA = 'SIM' and $P{para1} = 'BENPROBOLSAFAMILIA' OR BENPROVIVALEITE = 'SIM' and $P{para1} = 'BENPROVIVALEITE' OR BENPROVIVALEITEIDOSO = 'SIM' and $P{para1} = 'BENPROVIVALEITEIDOSO' OR BENPROPETI = 'SIM' and $P{para1} = 'BENPROPETI' OR BENPROPROGER = 'SIM' and $P{para1} = 'BENPROPROGER' OR BENPROLOAS = 'SIM' and $P{para1} = 'BENPROLOAS' OR BENPROLOASDEF = 'SIM' and $P{para1} = 'BENPROLOASDEF' OR BENPROPRONAF = 'SIM' and $P{para1} = 'BENPROPRONAF' OR BENPROGPAIF = 'SIM' and $P{para1} = 'BENPROGPAIF' OR BENPROPREVIDENCIA = 'SIM' and $P{para1} = 'BENPROPREVIDENCIA' OR BENPROPROJOVEM = 'SIM' and $P{para1} = 'BENPROPROJOVEM' OR BENPROPROJOVEMURB = 'SIM' and $P{para1} = 'BENPROPROJOVEMURB' OR BENPROPROJOVEMCAMP = 'SIM' and $P{para1} = 'BENPROPROJOVEMCAMP' OR BENPROPROJOVEMTRAB = 'SIM' and $P{para1} = 'BENPROPROJOVEMTRAB' OR BENPROMELHORIASANITARIA = 'SIM' and $P{para1} = 'BENPROMELHORIASANITARIA' OR BENPROHABINTSOC = 'SIM' and $P{para1} = 'BENPROHABINTSOC' OR BENPROUPA = 'SIM' and $P{para1} = 'BENPROUPA' OR BENPROHABBRAS = 'SIM' and $P{para1} = 'BENPROHABBRAS' OR BENPROPROMORAD = 'SIM' and $P{para1} = 'BENPROPROMORAD' OR BENPROMINCASMINVID = 'SIM' and $P{para1} = 'BENPROMINCASMINVID' OR BENPROOPRCOLET = 'SIM' and $P{para1} = 'BENPROOPRCOLET' OR BENPROPROMUNICIP = 'SIM' and $P{para1} = 'BENPROPROMUNICIP' and s.setcodigo = 1 and b.BENLOGCODIGO = l.logcodigo and e.hisententcodigo = ent.entcodigo and ent.entcodigo =3 and e.hisentdtaini = '2011/10/11' and e.hisentdtasai is null;

Foi uma boa solução, menos gambiarrística que muitas que já vi por aí.

Criado 11 de outubro de 2011
Ultima resposta 11 de out. de 2011
Respostas 7
Participantes 3