Jump to content
We've recently updated our Privacy Statement, available here ×

Hashmap problem(multivalues against a single key)


neetikamittal

Recommended Posts

Hi Friends,

Hopefully One of u have gone through mine problem.

My problem is I have one parameter named $P{homephone}

to display the runtime filled values from database.

that HomePhone field is of char[10] in database.

So I declared that parameter of type java.lang.String

 

but wen I am running a particular query,multiple values will be returned in result set so I created a arraylist of those values to put against that single key.

then I convert that arraylist to string array,so that value can be filled in.

 

But I think when running or filling up the report,that parameter defined their is not iterating the values rather it is giving an error.

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.

 

I am attaching a code snippet and also jrxml file for reference.

 

Plz have a look at it.

try{

JasperDesign jasperDesign = JRXmlLoader.load(reportFile);

 

JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

Class.forName("com.mysql.jdbc.Driver");

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

PrintWriter out = res.getWriter();

Map hmap=new HashMap();

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

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

if(cb1.equals("on"))

{

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

stmt.setString(1,name);

ResultSet rs = stmt.executeQuery();

ArrayList names = new ArrayList();

while (rs.next()) {

 

names.add(rs.getString("homePhone"));

}

Object ia[] = names.toArray();

int len=ia.length;

String[] s1=new String[len];

for(int i=0;i<len-1;i++)

{

s1= ia.toString();

 

}

 

hmap.put("homephone",s1);

//see here an string array is against a single key,I want that rarameter defined in report,iterate through this array and give the respective values.

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

// hphones.put("homephone",rs.getString("homePhone"));

hmap.put("firstname",name);

 

 

 

 

 

 

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

JRHtmlExporter exporter = new JRHtmlExporter();

Map imagesMap = new HashMap();

req.getSession().setAttribute("IMAGES_MAP",imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

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

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,out);

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.FALSE);

exporter.exportReport();

 

 

[file name=ctisreport1-358199458018b4d15c8080966996a531.jrxml size=22891]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/ctisreport1-358199458018b4d15c8080966996a531.jrxml[/file]

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi.

 

I'm not sure what you're trying to achieve but you get the error because you try to pass an Array:

Code:
String[] s1=new String[len]; 

(of Strings, sure but still an Array) for the homephone parameter

Code:
[code] hmap.put("homephone",s1);

where the engine expects to see a String:

Code:
[code]<parameter name="homephone" isForPrompting="false" class="java.lang.String">

 

HTH,

Grzewal

Link to comment
Share on other sites

ya I fully understand this

But how can I iterate through that array to have corresponding values.

also how to fill that $P{homephone} with different values for each person whose first name is 'amber'or smthing else.

 

I didn't find any type other that that where I can define the parameter type as array.

 

Is there any mechanism that can fill the values one by one that is in array?

 

first name is fine but $P{homephone} will be having different values .

problem is there.

 

Thanks

Neetika

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