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

(Hashmap problem)parameter field is empty


neetikamittal

Recommended Posts

Hi,

My problem is.

I want to populate the parameter values against a single key .

I created a parameter named homephone ($P{homephone})

of type String as in database values r of type char[10]

 

then in report design I place the same parameter on the detail section.

 

I tried the below code(giving an arraylist values to a single key.and then converting those arraylist values into an array and then to a string array as my parameter is of type string.

so plz have a look at the code.

and also I am attaching jrxml file for reference.

 

public void runReport(String databaseName, String userName, String password,String reportFile,HttpServletResponse res,HttpServletRequest req)

{

 

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 hphones=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<ia.length;i++)

{

s1= ia.toString();

 

}

 

hphones.put("homephone",s1);

 

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

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

hphones.put("firstname",name);

}

 

 

 

 

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,hphones,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-462ed27cef2de3dc5c0ba85b3aa7badd.jrxml size=22880]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/ctisreport1-462ed27cef2de3dc5c0ba85b3aa7badd.jrxml[/file]

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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