Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i create table dynamically for the hashmap values
    primarykey
    data
    text
    <p>I have successfully stored my database values inside the hashmap. How do I display the hashmap values in my jsp page in a dynamically changing table. see my action class below, here marketplace represents Country. for each country there are 4 values which are count, dataamount, result, orderdate.</p> <pre><code>package com.pkg; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class JanuaryAction { private String from; // creating variables to access input values. private String to; // creating variables to access input values. Map abc1 = new HashMap(); // Getting the map objects to store tha values public Map getAbc1() { /* Creating the setters and getters */ return abc1; } public void setAbc1(Map abc1) { this.abc1 = abc1; } public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } public String getTo() { return to; } public void setTo(String to) { this.to = to; } public Map&lt;String, String&gt; getAbc() { return abc; } public void setAbc(Map&lt;String, String&gt; abc) { this.abc = abc; } Map&lt;String, String&gt; abc = new HashMap&lt;String, String&gt;(); Map&lt;String, List&lt;ReportClass&gt;&gt; map = new HashMap&lt;String, List&lt;ReportClass&gt;&gt;(); // Using // Map // interface // implementing // hashmap public Map&lt;String, List&lt;ReportClass&gt;&gt; getMap() { return map; } public void setMap(Map&lt;String, List&lt;ReportClass&gt;&gt; map) { this.map = map; } public String execute() throws Exception { String fromdate = getFrom(); System.out.println(fromdate); String todate = getTo(); System.out.println(todate); Connection con = GetCon.getCon(); Statement statement = con.createStatement(); ResultSet resultset = statement .executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate &gt;='" + fromdate + "' AND OrderDate &lt;='" + todate + "' GROUP BY OrderDate,MarketPlace"); while (resultset.next()) { String marketplace = resultset.getString(1);// get the first column // in marketplace String orderdate = resultset.getString(2);// get the second column // in orderdate Double datamount = resultset.getDouble(3);// get the third column in // datamount Integer count = resultset.getInt(4);// get the fourth column in // count Double result = resultset.getDouble(5); // get the fifth column in // result ReportClass a = new ReportClass(); // create an object to access // pojo class. a.setMarketplace(marketplace); // setting the values in pojo class a.setOrderdate(orderdate); a.setDataamount(datamount); a.setCount(count); a.setResult(result); if (map.get(marketplace) != null) { // if the value in marketplace // is null then go to else // statement or go to if // statement. map.get(marketplace).add(a); // using the key add one complete // row values from a to // marketplace } else { List&lt;ReportClass&gt; optionsVO = new ArrayList&lt;ReportClass&gt;(); // create // a // list // optionsVo optionsVO.add(a); // store Reportclass values in List. map.put(marketplace, optionsVO); // storing it in map. /* System.out.println(map.get(marketplace).toString()); */ } } Set s = map.entrySet(); // A map entry (key-value pair).creating Set // interface. Iterator i = s.iterator(); while (i.hasNext()) { List&lt;ReportClass&gt; tempList = (List&lt;ReportClass&gt;) ((Entry) i.next()).getValue(); // creating // a // temporary // list for (ReportClass reportClassObj : tempList) { System.out.println(reportClassObj.getMarketplace());// display // values. System.out.println(reportClassObj.getDataamount()); System.out.println(reportClassObj.getOrderdate()); System.out.println(reportClassObj.getCount()); System.out.println(reportClassObj.getResult()); } } /* System.out.println(map.size()); */ return "success"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload