Jump to content

Sending SQL query from Java application


booyeeka

Recommended Posts

Hi all!

 

Can you help me how to send complete SQL query into JasperReports, from Java code.

 

If in Java code I send (put) one parameter, like:

 

Code:

String empid = "3";
reportParam.put("EMPID", empid);

 

... this example works, by a simple call of next query in Jasper's XML file:

 

Code:
[code]
select * from employees where Employee_ID = $P{EMPID}

 

BUT, when I try to call query in java file like :

 

Code:
[code]
String empid = "select * from employees where Employee_ID = 3";
reportParam.put("EMPID", empid);

 

... with $P{EMPID} only defined in jasper file, I get the following error:

 

Code:
[code]
java.lang.NullPointerException

 

 

Can you tell me where is my mistake?

 

Thank you in advance!

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

It looks like I did manage to solve my problem.

 

In Jasper Report Query, I defined parameter as :

 

$P!{EMPID}

 

 

... and it works good.

 

 

I post this, because I noticed that a lot of JasperReports user have same problem.

 

But BTW, JasperReports really rocks!

Link to comment
Share on other sites

  • 3 years later...

Hi!

 

I'm facing similar issues, about sending a complete query from my java application to my .jrxml file.

In this last file I define the parameter like that:

<parameter name="queryReport" class="java.lang.String"/>

<queryString>
        <![CDATA[$P!{queryReport}]]>
 </queryString>

 

When I print the report what I get it's the query  ( SELECT .... FROM ...) and not the result like it was suposed.

What I'm doing wrong?

Any Ideias....

Thanks

 

Link to comment
Share on other sites

  • 13 years later...

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