Jump to content
Changes to the Jaspersoft community edition download ×

Hashmap problem(mutiple values to single key)


Recommended Posts

Hi Friends,

So far now I have successfully generated a web based reports

Now I am trying to generate a report based on input form parameters.

I have a input form having a input field of name and a checkbox option regarding homephone no.

so based on the name given and checkbox option (yes)

report will give list of all the persons of that name and their respective homephone nos.


my problem is in HASHMAP parameter how can I associate multiple values to a single key.

here is the code snippet.

Name field is printing very well.

but wat about the phone nos.

I tried arraylist but it is giving a error.

Plz have a look at it.

I checked it

values of arraylist are stored very well against homephone key.

but while generating report it is giving error:--->


Could not create the report Incompatible java.util.ArrayList value assigned to parameter homephone in the ctisreport1 dataset. Incompatible java.util.ArrayList value assigned to parameter homephone in the report1 dataset.



JasperDesign jasperDesign = JRXmlLoader.load(reportFile);


JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);


Connection jdbcConnection = DriverManager.getConnection(databaseName,userName,password);

PrintWriter out = res.getWriter();

Map hphones=new HashMap();

String name = req.getParameter("firstName");

String cb1 = req.getParameter("homeinfo");



PreparedStatement stmt = jdbcConnection.prepareStatement("select firstName, homePhone from person where firstName = ?");


ResultSet rs = stmt.executeQuery();

ArrayList names = new ArrayList();

while (rs.next()) {





//String s = rs.getString("homePhone");









JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,hphones,jdbcConnection);

JRHtmlExporter exporter = new JRHtmlExporter();

Map imagesMap = new HashMap();


exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);







It seems like report is having problem in filling values of homephone nos in the parameter given in report .

I also created two parameters which I defined here during Ireport design.


Thanks(hope to hear soon)


Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic


In the database homephone is defined as type char[10]

not of String type.


So I defined a parameter homephone with type as



and default expression as new String("")


I am attaching the jrxml file.

plz have a look at it.



Neetika [file name=ctisreport1.jrxml size=22944]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/ctisreport1.jrxml[/file]

Link to comment
Share on other sites


I tried to convert the arraylist into an atring array.

Phonenos from database are printing very well on console.

But in Parameter field values r not coming up.

it is empty.

can't I put a string array against a single key in hashmap.

or I need to do something else so that phonenos can comein from database against the name entered by user.

like if user puts "amber"

and click checkbox HOMEPHONE as he wants to see the phonenos of all the persons whose name is "amber"


and datatype for homePhone in database is char[10].

then wat I need to do .

I tried the code attached below and now it is giving the error in tomact log file as

Could not create the report Incompatible [Ljava.lang.String; value assigned to parameter homephone in the ctisreport1 dataset. Incompatible [Ljava.lang.String; value assigned to parameter homephone in the ctisreport1 dataset.



today only I posted a query with all my code and jrxml file.


U can have a look at that.






Post edited by: neetikamittal, at: 2006/09/06 00:20

Post edited by: neetikamittal, at: 2006/09/06 00:22

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