problems with hashtable(how to get keys knowing values)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: problems with hashtable(how to get keys knowing values)

  1. #1
    Tanya Guest

    problems with hashtable(how to get keys knowing values)


    Hi,
    I have a problem and any help would be greatly appreciated!

    I have hashtable like that:
    Hashtable category = new Hashtable();

    category.put("XREF_STATE_CODE", "Global Setup");
    category.put("XREF_STATE_COUNTRY", "Global Setup");
    category.put("PROPERTY_CONTACT", "Property Setup");
    category.put("PROPERTY_DESC", "Property Setup");
    category.put("RENTABLE_GROUP", "Property Setup");
    category.put("RENTABLE_DAY", "Property Setup");
    category.put("HMA_STATEMENT", "Invoicing");
    category.put("RA_TRANSACTION", "Invoicing");
    category.put("RA_INVOICE", "Invoicing");
    category.put("INVOICE_COMMENT", "Invoicing");

    where key is table_name and value is a category which each table_name related
    to. Knowing table_name I can easily to get value(category). The problem is
    how knowing category(value of hashtable) to get table_names (keys) that related
    to this category.
    Thanks in advance.
    Tanya.




  2. #2
    Paul Clapham Guest

    Re: problems with hashtable(how to get keys knowing values)


    Tanya <tgrishnin@reserveamerica.com> wrote in message
    news:393ebd72$1@news.devx.com...
    >
    > Hi,
    > I have a problem and any help would be greatly appreciated!
    >
    > I have hashtable like that:
    > Hashtable category = new Hashtable();
    >
    > category.put("XREF_STATE_CODE", "Global Setup");
    > category.put("XREF_STATE_COUNTRY", "Global Setup");
    > category.put("PROPERTY_CONTACT", "Property Setup");
    > category.put("PROPERTY_DESC", "Property Setup");
    > category.put("RENTABLE_GROUP", "Property Setup");
    > category.put("RENTABLE_DAY", "Property Setup");
    > category.put("HMA_STATEMENT", "Invoicing");
    > category.put("RA_TRANSACTION", "Invoicing");
    > category.put("RA_INVOICE", "Invoicing");
    > category.put("INVOICE_COMMENT", "Invoicing");
    >
    > where key is table_name and value is a category which each table_name

    related
    > to. Knowing table_name I can easily to get value(category). The problem is
    > how knowing category(value of hashtable) to get table_names (keys) that

    related
    > to this category.
    > Thanks in advance.
    > Tanya.
    >
    >

    Hashtable is designed to map keys to values, as its documentation says. You
    could design your own class that stored pairs of strings (another class or a
    string array) in a Vector and provided methods to extract by the first or
    second string, or you could put your strings in a database and use SQL to do
    what you want.




  3. #3
    Tanya Guest

    Re: problems with hashtable(how to get keys knowing values)


    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >
    >Tanya <tgrishnin@reserveamerica.com> wrote in message
    >news:393ebd72$1@news.devx.com...
    >>
    >> Hi,
    >> I have a problem and any help would be greatly appreciated!
    >>
    >> I have hashtable like that:
    >> Hashtable category = new Hashtable();
    >>
    >> category.put("XREF_STATE_CODE", "Global Setup");
    >> category.put("XREF_STATE_COUNTRY", "Global Setup");
    >> category.put("PROPERTY_CONTACT", "Property Setup");
    >> category.put("PROPERTY_DESC", "Property Setup");
    >> category.put("RENTABLE_GROUP", "Property Setup");
    >> category.put("RENTABLE_DAY", "Property Setup");
    >> category.put("HMA_STATEMENT", "Invoicing");
    >> category.put("RA_TRANSACTION", "Invoicing");
    >> category.put("RA_INVOICE", "Invoicing");
    >> category.put("INVOICE_COMMENT", "Invoicing");
    >>
    >> where key is table_name and value is a category which each table_name

    >related
    >> to. Knowing table_name I can easily to get value(category). The problem

    is
    >> how knowing category(value of hashtable) to get table_names (keys) that

    >related
    >> to this category.
    >> Thanks in advance.
    >> Tanya.
    >>
    >>

    >Hashtable is designed to map keys to values, as its documentation says.

    You
    >could design your own class that stored pairs of strings (another class

    or a
    >string array) in a Vector and provided methods to extract by the first or
    >second string, or you could put your strings in a database and use SQL to

    do
    >what you want.
    >
    >
    >

    Thanks Paul!
    I just needed that hashtable in other methods of my class and wanted to use
    it for this particular task without creating additional object. Here is my
    solution:

    if (Category != null) { //Category is a variable that's passed by
    /**
    * Gets keys (table_names) and puts it into the vector v depending on category
    */
    Enumeration en = category.keys();
    while (en.hasMoreElements()) {
    String s = (String)en.nextElement();
    String r = (String)category.get(s);
    if (r.equals(Category))
    { v.addElement(s); }

    }
    if (v.size() != 0) {
    lsSql.append(" and xt.table_name = ?");

    try {
    loCon = coPool.getConnection();
    ps = loCon.prepareStatement(lsSql.toString());
    for (int j = 0; j < v.size(); j++) {
    ps.setString(1, (String)v.elementAt(j));
    ResultSet rs1 = ps.executeQuery();

    while (rs1.next()) {
    ................................................
    ..................................... and so on.....



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center