�Map String, List ?

Hello!
In my application I would like to use a data type to represent a pair "<city1>, <inferior limit>", "<city1>, <superior limit>", "<city2>, <inferior limit>", "<city2>, <superior limit>", "<city3>, <inferior limit>", "<city3>, <superior limit>", etc. So when I looked for the first element (city) I'd get two values (two limits).
What would be the best option?
I thought I could use for example:
Map<String, List> map = new HashMap<String, List>();
"String" will have the name and "List" will have two elements: inferior and superior limit.
If this were reasonable option, how could I put elements in that map? And how could I get the limits?
Thanks in advance :)

You shouldn't use List for this purpose: you have exactly 2 elements of certain meaning (not collection of numerous elements), so you should better create a class to hold them and use Map<String,YourClass>.

Similar Messages

  • JPA2 Question: Is it possible to map a Map(enum, List String ) in JPA2?

    Is it possible to map a Map(enum, List<String>) in JPA2? Or do I have to create a separate Entity class that maps each List<String> collections for each possible value in the enum?
    Edited by: user7976113 on Jan 22, 2010 7:51 PM
    Edited by: user7976113 on Jan 22, 2010 7:51 PM

    No, JPA does not support this or any nested collection type of mappings directly.
    The best solution is to create an Entity or Embeddable to contain the collection data.
    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Nested_Collections.2C_Maps_and_Matrices
    James : http://www.eclipselink.org

  • Regarding Month sorting in List Map String, Object

    Dear All,
    i have a list which is- List<Map<String, Object>> results . What i need is i want to sort the 'results ' .The values in results, when i tried to print it are
    RESULTS :{Apr 2009}
    RESULTS :{August 2008}
    RESULTS :{December 2008}
    RESULTS :{Feb 2009}
    RESULTS :{Jan 2009}
    RESULTS :{Jun 2009}
    RESULTS :{Mar 2009}
    RESULTS :{May 2009}
    RESULTS :{Nov 2008}
    RESULTS :{October 2008}
    RESULTS :{Sep 2008}
    i want to sort the values according to the month. like jan 2008,feb 2008 etc .
    Somebody please help .
    Thanks in advanced .

    sha_2008 wrote:
    The output sholud be june 2008,Dec 2008, Mar 2009. ie according to the increase order of monthsThat doesn't make it any clearer, in the example "June 2008" and "Mar 2009" are in the same map. Do you want that map to appear both before and after "Dec 2008" which doesn't make sense or are you expecting to restructure the data. If so, I would suggest you use a SortedMap like;
    List<Map<String,Object>> maps = ...
    SortedMap<String, Object> results = new TreeMap<String, Object>(dateComparator);
    for(Map<String, Object> map: maps)
       results.putAll(map);BTW: is there any good reason your dates are Strings instead of Date objects which are much easier to sort?

  • How to use Multimaps (Map String, ArrayList String )

    I was using an array to store player names, userIDs, uniqueIDs, and frag counts, but after reading about multimaps in the tutorials, it seems that would be much more efficient. However, I guess I don't quite understand it. Here's how I wanted things stored in my string array:
    String[] connectedUsers = {"user1_name", "user1_userid", "user1_uniqueid", "user1_frags"
                                            "user2_name"...}and here is how I'm attempting to setup and use the 'multimap':
    public class Main {
        static Map<String, ArrayList<String>> connectedUsers;
        public void updatePlayers(String name, String status) {
            String[] statusSplit = status.split(" ");
            if (connectedUsers.containsKey(name)) {
                connectedUsers.put(name, statusSplit[0]);
            else {
                connectedUsers.put(name, statusSplit[0]);
        }It's quite obvious I don't understand how this works, but should I even set this multimap up this way? Perhaps I should use a regular map with a string array for the values?

    You're cool MrOldie. Its just that alarm bells start ringing in my head when people come on and post as much as you do.
    * Created on Jul 28, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeSet;
    * ManyMap is a map that allows more than one value to be stored with any key
    * <p>
    * There are a number of methods in the class that have been deprecated because
    * the original functionality of Map has been violated to accomodate the concept
    * of the ManyMap
    public class ManyMap<T, T2> implements Map<T, T2> {
         private HashMap<T, ArrayList<T2>> mInnerMap;
         public ManyMap() {
              mInnerMap = new HashMap<T, ArrayList<T2>>();
          * @deprecated
         public T2 get(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.get(0);
         public Iterator<T2> getAll(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.iterator();          
         public T2 put(T obj1, T2 obj2) {
              ArrayList<T2> ar = _getNotNull(obj1);
              ar.add(obj2);
              return obj2;
         public Set<Map.Entry<T, T2>> entrySet() {
              TreeSet<Map.Entry<T, T2>> entries = new TreeSet<Map.Entry<T, T2>>();
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   Iterator<T2> vals = mInnerMap.get(key).iterator();
                   while (vals.hasNext()) {
                        Entry<T, T2> entry = new Entry<T, T2>(key, vals.next());
                        entries.add(entry);
              return entries;
         public int size() {
              return mInnerMap.size();
         public int valuesSize() {
              int vals = 0;
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   ArrayList<T2> ar = mInnerMap.get(key);
                   vals += ar.size();
              return vals;
         public void clear() {
              mInnerMap.clear();
         public void putAll(Map<? extends T, ? extends T2> map) {
              Iterator _i = map.entrySet().iterator();
              while(_i.hasNext()) {
                   Map.Entry<? extends T, ? extends T2> entry = (Map.Entry<? extends T, ? extends T2>) _i.next();
                   put(entry.getKey(), entry.getValue());
         public Collection <T2> values() {
              LinkedList ll = new LinkedList();
              Iterator<ArrayList<T2>> _i = mInnerMap.values().iterator();
              while (_i.hasNext()) {
                   ll.addAll(_i.next());
              return ll;
         public boolean containsValue(Object val) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              while (values.hasNext()) {
                   if (values.next().contains(val)) return true;
              return false;
         public boolean containsKey(Object key) {
              return mInnerMap.containsKey(key);
         public T2 remove(Object obj) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              boolean found = false;
              while (values.hasNext()) {
                   if (values.next().remove(obj)) {
                        found = true;
              return found ? (T2)obj : null;
         public boolean isEmpty() {
              return valuesSize() == 0;
         @SuppressWarnings("hiding")
         private class Entry<T, T2> implements Map.Entry<T, T2> {
              T key;
              T2 val;
              public Entry (T obj1, T2 obj2) {
                   key = obj1;
                   val = obj2;
              public T2 getValue() {
                   return val;
              public T getKey() {
                   return key;
              public T2 setValue(T2 obj) {
                   return val = obj;
         public Set<T> keySet() {
              return mInnerMap.keySet();
         public ArrayList<T2> _get (Object obj) {
              return mInnerMap.get(obj);
         public ArrayList<T2> _getNotNull (T obj) {
              ArrayList<T2> list = _get(obj);
              if (list == null) {
                   list = new ArrayList<T2>(1);
                   mInnerMap.put(obj, list);
              return list;
    }Edited by: tjacobs01 on Aug 19, 2008 12:28 PM

  • How mapping sharepoint list Columns to Sql server data table columns programaticlly

    Hi ,
     I have one Verification List in share Point ,in that list i have 10 columns.And we have sql server in that sql server we have one data table Verification_Table
    in that table we have 25 column, my requirement is all list data  move to  sql data table[ what ever columns mapping to list--->data table that data store in data table reaming column is  Null]
     using grammatically not in BCS

    Hello,
    You can create SQL connection and use Datareader to read from SQL.Firs create a connection string and put this string in web application web.config file of your sharepoint site.
    Now use below code to call your connectionstring in your webpart.
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
    Here is link to read the data from SQL:
    http://www.akadia.com/services/dotnet_data_reader.html
    Here is one MSDN link to read SP list data:
    http://msdn.microsoft.com/en-us/library/dd490727%28v=office.12%29.aspx
    Let me know if you have any doubt
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Use of dsp:select with some map or list???

    Dear Friends,
    I want to use dsp:select by using map or list as the option of the given combobox using repository. Can anybody help me out to resolve my problem. Thanks to in advance.
    Regards,
    Girish Mishra

    Hi,
    You can use the below snippet.
    <dsp:select bean="YourBean.value">
    <dsp:droplet name="ForEach">
    <dsp:param name="array" param="YourList"/>
    <dsp:oparam name="output">
    <dsp:option><dsp:valueof param="element"/></dsp:option>
    </dsp:oparam>
    </dsp:droplet>
    </dsp:select>
    You have to set the list from the repository before you render this page.
    Hope this helps.
    Keep posting the updates / questions.
    Thanks,
    Gopinath Ramasamy

  • Convert Map String, Object to Map String,String ?

    How can I convert a map say;
    Map<String, Object> map = new Map<Striing, Object>();
    map.put("value", "hello");
    to a Map<String,String>.
    I want to pass the map to another method which is expecting Map<String,String>.
    Thanks

    JoachimSauer wrote:
    shezam wrote:
    Because im actaully calling an external method to populate map which returns <String, Object>.Now we're getting somewhere.
    Oh wait, no, we're not! We're back to my original reply:
    What do you want and/or expect to happen if one of the values isn't actually a String object but something else?Nothing like a bit of confusion :). They are and always will be String objects.
    So this external method, call it external1 for now returns a Map<String, Object>, I then want to pass this map to another external method external2 which takes Map <String,String> as a parameter.

  • Convert Map String, Object   to    Map Object, Object

    is there any way to convert a map of type Map<String, Object> to a map of type Map<Object, Object>? I tried casting it did not work

    You can also take the long way around:
        Map<Object, Object> map = (Map<Object, Object>)buildMapObject(
          new String[] { "1", "2", "3" },
          new Object[] { new Integer(1), new Integer(100), new Integer(1000) });
      public Object buildMapObject(String[] s, Object[] o) {
        Map<String, Object> map = new HashMap<String, Object>();
    // Populate map from arguments
        return map;
      }Though why you'd want to do that is beyond me.

  • Using Map and List, simple

    Hi,
    My prolem is very simple, but i'm beggining with java.
    I have 10 key-values: "CUSTOMER_ID" , the others are not important
    What is important is that I want to have different values under the same key CUSTOMER_ID
    The structure should be like this:
    CUSTOMER_ID 5
    CUSTOMER_ID 1
    CUSTOMER_ID 4
    OFFICE_ID 33
    SOME_KEY 10
    SOME_OTHER_KEY 123
    Which structure can I use?
    can I use Java Map?
    List?
    Other?
    and how to insert this values and how to load it?
    Please show me simple code

    Everything you need to know: The Java� Tutorial - Java� Collections Framework

  • SelectItems and Map String,String

    Hi all -
    I'm using Tomcat 6.0.14, JSF 1.2 and JSTL 1.2.
    Consider the following code:
    <h:selectOneListBox size="1" value="#{myBean.value}">
      <f:selectItems value="#{myBean.valueMap}"/>
    </h:selectOneListBox>And consider the following Map<String,String>, which is returned by myBean.getValueMap():
    Key: Value
    AL: Alabama
    AR: Arkansas
    The result of displaying the above map with the above code is:
    <select name="blahblah" size="1">
      <option value="Arkansas">AR</option>
      <option value="Alabama">AL</option>
    </select>Shouldn't it display like this?
    <select name="blahblah" size="1">
      <option value="AL">Alabama</option>
      <option value="AR">Arkansas</option>
    </select>if not, how do I make it display like I want it?
    Thanks
    Tim

    Kaydet81 wrote:
    Hi all -
    I'm using Tomcat 6.0.14, JSF 1.2 and JSTL 1.2.
    Consider the following code:
    <h:selectOneListBox size="1" value="#{myBean.value}">
    <f:selectItems value="#{myBean.valueMap}"/>
    </h:selectOneListBox>And consider the following Map<String,String>, which is returned by myBean.getValueMap():
    Key: Value
    AL: Alabama
    AR: Arkansas
    The result of displaying the above map with the above code is:
    <select name="blahblah" size="1">
    <option value="Arkansas">AR</option>
    <option value="Alabama">AL</option>
    </select>Shouldn't it display like this?
    <select name="blahblah" size="1">
    <option value="AL">Alabama</option>
    <option value="AR">Arkansas</option>
    </select>
    The javadoc for UISelectItems clearly states that the keys are used as the labels and the values for the, well, values.
    >
    if not, how do I make it display like I want it?Invert your map or create a method that will create the SelectItem objects from the map the way you want them.

  • Nr of elements in string[] list ?

    Hi,
    is there easy way to find out how many Strings (object) there are in a string[] buffer.
    I have a method :
    myMethod(string[] list)
    // here i want to find out how many Strings are passed into this method
    thanks
    Indy

    int numStrings = list.length;

  • Compressing and decompressing a  string list

    Hi All,
    i need a help:
    i have an string list say,
    String sample="test";
    String sample1="test1";
    String sample2="test3";
    i want to compress this sample,sample1,sample2 and store that compressed results into another string variable.
    Ex:
    compressedSample=sample;
    compressedSample1=sample1;
    compressedSample2=sample2;
    similarly how can i uncompress the compressedSample,compressedSample1,compressedSample2 variables.
    Thanks in advance

    Try something like this :
    Compressing :
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(aos);
    byte[] ba = "the_string_to_compress".getBytes();
    gos.write(ba,0,ba.length);
    gos.flush();
    String compressed_string = aos.toString();
    gos.close();
    Decompressing :
    GZIPInputStream zin = new GZIPInputStream( new ByteArrayInputStream( compressed_string.getBytes() ) );
    StringBuffer dat = new StringBuffer();
    byte[] buf = new Byte[128];
    for(int r; (r=zin.read(buf))!=-1;) dat.append( new String(buf,0,r) );
    zin.close();
    String org_string = dat.toString();

  • Mapping String to String

    Hi ALL,
    How can we map string of same structure to another string? Do we need to map each field?
    Please advice.
    Thanks,
    Kiran.

    Hi,
    >>How can we map string of same structure to another string? Do we need to map each field?
    If it is a field mapping you have to map each source field to target field.
    or
    If you are talking about the segment mapping and if both the source and target structures are same, then in message mapping there is an option to map all the fields(the fields with identical name swill get mapped automatically)

  • Please Help::How to display a Map with LIsts as Keys and Values using JSTL

    Hi,
    I need some assistance on how to display a Map in JSP using struts or core JSTL. I have a HashMap which has a List of keys and each key maps to a value of an ArrayList.i.e I have an ArrayList of taxCodes and each taxCode maps to a value of taxDetails which is an ArrayList of details for for that particular taxCode. I have some trouble to display each taxCode then display taxDetails for each taxCode. Here is my code below:
    OrderDetails.java
    package orderitems;
    import java.sql.*;
    import java.util.*;
    public class OrderDetails {
        private LineOder lineOrder;
        private Map lineItems;
        //returns an item number, key_item, from its unique keys
        public int getItemNumber(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            int itmNum = 0;
             * key_item a unique number for an item.
             * key_year,key_office,key_client,key_company unique keys
             * for each order where this key_item is taken
             * from.
            String select = "SELECT key_item FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + key_item +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                if(rst.next()){
                    itmNum = Integer.parseInt(rst.getString("key_item"));
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itmNum;
        //get a list of item number(item codes)
        public List getAllItemNumbers(String key_year,
                String key_office,String key_client,String key_company){
            List itemNumbers = new ArrayList();
            LineItem itemNumber = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            String select = "SELECT key_item FROM "+ Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    itemNumber = new LineItem();
                    itemNumber.setKey_item(Integer.parseInt(rst.getString("key_item")));
                    itemNumbers.add(itemNumber);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemNumbers;
        //get a list of tax codes
        public List getAllTaxCodes(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            ItemTax taxCode;
            List taxCodes = new ArrayList();
            int itemNum = getItemNumber(key_item, key_year,
                    key_office,key_client,key_company);
            String select = "SELECT key_tax_code FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + itemNum +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    taxCode = new ItemTax();
                    taxCode.setKey_tax_code(rst.getString("key_tax_code"));
                    taxCodes.add(taxCode);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return taxCodes;
        /////This methode returns a Map which am trying to display in JSP
        //use tax code to get tax details
        public Map getItemTaxDetails(String key_year,String key_office,
                String key_client,String key_company,int key_item){
            ItemTax taxDetail = null;
            List taxDetails = new ArrayList();
            List itemTaxCodes = new ArrayList();
            Map itemTaxDetails = new HashMap();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //get a list of all tax codes of an item with a
            //given item number
            itemTaxCodes = getAllTaxCodes(key_item,key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator taxCodeIter= itemTaxCodes.iterator(); taxCodeIter.hasNext();){
                    ItemTax itemTaxCode = (ItemTax)taxCodeIter.next();
                    String taxCode = itemTaxCode.getKey_tax_code();
                    String select = "SELECT tax_type,tax_value," +
                            "tax_limit_val FROM "+ Constants.WEB_TABLE +
                            " WHERE key_item = "+ key_item +
                            " AND key_year = '" + key_year + "'" +
                            " AND key_office = '" + key_office + "'" +
                            " AND key_client = '" + key_client + "'" +
                            " AND key_company = '" + key_company +"'" +
                            " AND key_tax_code = '" + taxCode + "'";
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        taxDetail = new ItemTax();
                        //records to be displayed only
                        taxDetail.setKey_item(Integer.parseInt(rst.getString("key_item")));
                        taxDetail.setTax_value(rst.getString("tax_value"));
                        taxDetail.setTax_limit_val(Float.parseFloat(rst.getString("tax_limit_val")));
                        //////other details records ommited//////////////////////////
                        taxDetails.add(taxDetail);////An ArrayList of taxDetails for each taxCode
                     * A HashMap which has all taxCodes of an item as its keys
                     * and an ArrayList of taxdetails as its values.
                     * I return this for display in a JSP.
                    itemTaxDetails.put(taxCode,taxDetails);
                System.out.println();
                System.out.println("*********CONSOLE OUTPUT*************");//display on console
                Set set = itemTaxDetails.keySet();
                Iterator iter = set.iterator();
                System.out.println("Key\t\tValue\r\n");
                while (iter.hasNext()) {
                    Object taxCode=iter.next();
                    Object details=itemTaxDetails.get(taxCode);
                    System.out.println(taxCode +"\t" + details);
                System.out.println("************************************");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemTaxDetails;
        //details of an item with all its taxes
        public List getAllItemDetails(String key_year,
                String key_office,String key_client,String key_company){
            List lineItems = new ArrayList();
            List itemNumbers = new ArrayList();
            Map taxDetails = new HashMap();
            LineItem item = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //A list of all item numbers in the declaration
            itemNumbers = getAllItemNumbers(key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator itemIter= itemNumbers.iterator(); itemIter.hasNext();){
                    LineItem itemNum = (LineItem)itemIter.next();
                    int itemNumber = itemNum.getKey_item();
                    String select = "SELECT item_description,item_mass," +
                            "item_cost" +
                            " FROM " + Constants.WEB_TABLE +
                            " WHERE key_year = '"+key_year+"'" +
                            " AND key_office = '"+key_office+ "'"+
                            " AND key_client = '"+key_client+ "'"+
                            " AND key_company = '"+key_company+ "'"+
                            " AND key_item = " + itemNumber;
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        item = new LineItem();
                        item.setItem_description(rst.getString("item_description"));
                        item.setItem_mass(Float.parseFloat(rst.getString("item_mass")));
                        item.setKey_item(Integer.parseInt(rst.getString("item_cost")));
                        //////other details records ommited//////////////////////////
                        /* A HashMap of all itemTaxeCodes as its keys and an
                         * ArrayList of itemTaxedetails as its values
                        taxDetails = getItemTaxDetails(item.getKey_year(),item.getKey_office(),
                                item.getKey_client(),item.getKey_company(),item.getKey_item());
                        //item tax details
                        item.setItmTaxes(taxDetails);
                        //list of items with tax details
                        lineItems.add(item);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineItems;
        public Set getOrders(String key_year,String key_office,
                String key_client,String key_company){
            List lineItems = new ArrayList();
            Set lineOrders = new HashSet();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            LineOder lineOrder = null;
            String select = "SELECT * FROM " + Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    lineOrder = new LineOder();
                    lineOrder.setKey_year(rst.getString("key_year"));
                    lineOrder.setKey_office(rst.getString("key_office"));
                    lineOrder.setKey_client(rst.getString("key_client"));
                    lineOrder.setKey_company(rst.getString("key_company"));
                    ////list of items with all their details
                    lineItems = getAllItemDetails(lineOrder.getKey_year(),lineOrder.getKey_office(),
                            lineOrder.getKey_client(),lineOrder.getKey_company());
                    //setting item details
                    lineOrder.setItems(lineItems);
                    //a list of order with all details
                    lineOrders.add(lineOrder);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineOrders;
    Controller.java
    package orderitems;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Controller extends HttpServlet {
        private Map taxDetails = new HashMap();
        private OrderDetails orderDetails = null;
        protected void processRequest(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            String key_year = "2007";
            String key_office = "VZX00";
            String key_company = "DG20";
            String key_client =  "ZI001";
            int key_item = 1;
            String nextView = "/taxdetails_list.jsp";
            orderDetails = new OrderDetails();
            taxDetails = orderDetails.getItemTaxDetails(key_year,key_office,
                    key_company,key_client,key_item);
            //Store the collection objects into HTTP Request
            request.setAttribute("taxDetails", taxDetails);
            RequestDispatcher reqstDisp =
                    getServletContext().getRequestDispatcher(nextView);
            reqstDisp.forward(request,response);
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
    taxdetails_list.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <title>Simple Tax Detail Diaplay ::</title>
            <link rel="stylesheet" type="text/css" href="imgs/orders.css"/>
        </head>
        <body>
            <jsp:useBean id="taxDetails" class="java.util.HashMap" scope="request"/>
            <table>
                <c:forEach items="${taxDetails}" var="hMap">
                    <tr>
                        <td><c:out value="${hMap.key}" /></td>
                        <!--td><%--c:out value="${hMap.value}" /--%></td-->
                    </tr>
                </c:forEach>
            </table>
        </body>
    </html>am displaying taxCodes(in this case i have VAT and ICD) fine but cant figure out how to display a list of value for each taxCode.Here is the output am getting
    both in my JSP and on the console:
    *******************************CONSOLE OUTPUT****************************
    Key          Value
    ICD     [orderItems.ItemTax@13e6226, orderItems.ItemTax@9dca26]
    VAT [orderItems.ItemTax@13e6226, orderItems.ItemTax@9dca26]
    Edited by: aiEx on Oct 8, 2007 6:54 AM

    hi evnafets,
    yes i need a nested for loop.I have tried your advice but my bean properties are not found.Am getting this error:
    javax.servlet.ServletException: Unable to find a value for "key_item" in object of class "java.lang.String" using operator "."
    I have tried this as stated earlier in the post:I have tried to make the method getItemTaxDetails return a List and get the returned list value as taxDetails. I then tested to display this list on JSP and its displaying fine.
    public List getItemTaxDetails(String key_year,String key_office,
                String key_client,String key_company,int key_item){
            ItemTax taxDetail = null;
            List taxDetails = new ArrayList();
            List itemTaxCodes = new ArrayList();
            Map itemTaxDetails = new HashMap();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //get a list of all tax codes of an item with a
            //given item number
            itemTaxCodes = getAllTaxCodes(key_item,key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator taxCodeIter= itemTaxCodes.iterator(); taxCodeIter.hasNext();){
                    ItemTax itemTaxCode = (ItemTax)taxCodeIter.next();
                    String taxCode = itemTaxCode.getKey_tax_code();
                    String select = "SELECT tax_type,tax_value," +
                            "tax_limit_val FROM "+ Constants.WEB_TABLE +
                            " WHERE key_item = "+ key_item +
                            " AND key_year = '" + key_year + "'" +
                            " AND key_office = '" + key_office + "'" +
                            " AND key_client = '" + key_client + "'" +
                            " AND key_company = '" + key_company +"'" +
                            " AND key_tax_code = '" + taxCode + "'";
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        taxDetail = new ItemTax();
                        //records to be displayed only
                        taxDetail.setKey_item(Integer.parseInt(rst.getString("key_item")));
                        taxDetail.setTax_value(rst.getString("tax_value"));
                        taxDetail.setTax_limit_val(Float.parseFloat(rst.getString("tax_limit_val")));
                        //////other details records ommited//////////////////////////
                        taxDetails.add(taxDetail);////An ArrayList of taxDetails for each taxCode
                     * A HashMap which has all taxCodes of an item as its keys
                     * and an ArrayList of taxdetails as its values.
                     * I return this for display in a JSP.
                    itemTaxDetails.put(taxCode,taxDetails);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            //return itemTaxDetails;
            return taxDetails;
        }And my JSP
    taxdetails_list.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link rel="stylesheet" type="text/css" href="imgs/orders.css"/>
        </head>
        <body>
            <table>
                <c:forEach var="curRecord" items="${taxDetails}" varStatus="rowCounter">
                        <c:choose>
                            <c:when test="${rowCounter.count % 2 == 0}">
                                <c:set var="rowStyle" scope="page" value="odd" />
                            </c:when>
                            <c:otherwise>
                                <c:set var="rowStyle" scope="page" value="even" />
                            </c:otherwise>
                        </c:choose>
                        <tr class="${rowStyle}">
                            <td>${curRecord.key_item}</td>
                            <td>${curRecord.tax_value}</td>
                            <td>${curRecord.tax_limit_val}</td>
                        </tr>
                    </c:forEach>
            </table>
        </body>
    </html>I can't see where am going wrong even with your advice.Please help.
    Thnx.

  • How to get Resultset in a Map or List

    Hi
    I want to store the data returned by the resultset in an array or list or map. but i dont know how to do it.
    also i need to know once stored how can i retrieve those values..
    Instead of saying
    while (rs.next()) {
    String name = rs.getString("name");
    String values = rs.getString("value");
    int id = rs.getInt("Id"); }
    i want it to be
    while(rs.next())
    { Map dataMap = new HashMap();
    dataMap.put(rs.getObject()); }
    something like [1,name1, value1
    2, name2, value2] and so on
    Does anone have any suggestions?
    I did refer to the below example, but i think there must be a simpler way
    http://forum.java.sun.com/thread.jsp?forum=48&thread=484092
    Thank you

    Check out the Jakarta DBUtils package. It can return a resultset as a Map.

Maybe you are looking for

  • Caller ID on TV does not work.

    This feature has become so unreliable that I have had to make several calls and send emails to Verizon.  The last tech promised me that the problem was resolved for ever, but alas, the problem has returned.  No caller ID on TV.  It works OK on my pho

  • How do I connect two Apple IDs to iTunes?

    My wife an I are new to the world of Apple and are having fun finding our way.  We have muliple devices (iPhone4, iPhone5, iPad, iPad mini) and two separate iCloud apple IDs.  I want to share the iTunes library on my desktop computer with both IDs...

  • Textfelder Acrobat 9 Standart und Acrobat 7.0 Professional

    Hi, Ich nutzte zurzeit Adobe Acrobat 7.0 Professional. Wenn ich jetzt ein Textfeld erstelle kommt ein Menü mit folgende Registerkarten: Allgemein,Darsttelung, Optionen, Aktionen, Format, Validierung, Berechnung. Jetzt aber hab ich mal Adobe Acrobat 9

  • Send a ring tone via blue tooth

    hi!! im again!!,i want to know how i can send a ring tone or data via bluetooth to another device??

  • Segfaulting on full container operations - debugging help

    Hi all - I have some data that has been through lots of dbxml upgrades and the last two upgrades have full container operations segfaulting. I was able to ignore this data for a year but now its coming back to haunt me. All full container operations,