Problem in calling parameter value using jdbc connection



i have some issues when i try to send paramters map to jasper template. I set a simple HashMap and send to jasper report using fillReport() method as following:

Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("code", "myCode"); ......... JasperFillManager.fillReport(jasperReport, parameters, connection);

i used the following datasource:

String connectionURL = "jdbc:postgresql://" + hostName + ":5432/" + sid;                         connection = DriverManager.getConnection(connectionURL, userName, password);

In the template jrxml file i have the following code to retrieve and exec query:

<parameter name="code" class="java.lang.String"/> <queryString>   <![CDATA[select * from  mySchema.myTable where myField = $P{code}]]>  </queryString>

It doesn't throw any errors but it doesn't properly read the value of code parameters which i set before:

DEBUG JRJdbcQueryExecuter:362 - SQL query string: select * from  mySchema.myTable where myField = ? DEBUG JRJdbcQueryExecuter:569 - Parameter #1 (code of type java.lang.String): null

I have tried the project with two versions of JasperReport library (6.1.1 & 6.3.0) but still I have the same issue.

Please help me to sort out the issue.

Thanks in advance.

vijaycharan's picture
Joined: Jun 17 2016 - 12:47am
Last seen: 2 years 8 months ago

Just found that the parameters works fine if I give empty datasource

JRDataSource dataSource = new JREmptyDataSource();

But with the JDBC it doesn't work. Any suggestions please.

vijaycharan - 3 years 1 month ago

2 Answers:


Thanks for the reply.

I sorted out my problem, the parameter which i used is inside a subdataset but I have added the parameter only to the main dataset.

Now it works fine after adding the parameter inside the subdataset.


vijaycharan's picture
Joined: Jun 17 2016 - 12:47am
Last seen: 2 years 8 months ago

It works fine in both versions you've specified. You didn't include code on how you're setting "connection". You jasperreports code looks OK. Try testing if your jdbc connection is working OK by executing sql select to find if you can get result back.

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 2 months 1 week ago