Tuesday, December 24, 2013

Java Hash Map Set and get Data

Set Hash Map

 private TreeMap <String, String> itemMap = new TreeMap<String, String>();
     private TreeMap <String, String> itemMap1 = new TreeMap<String, String>();
     private void FillCombo_Items(){
       
         //int row = jTable_Roles.getSelectedRow();
          // jCombo_Items.removeAllItems();
           itemMap.clear();
           itemMap1.clear();
          
           String S;
           String sql = "Select stock_id,description,units from inventory_dcl_stock_master ORDER BY description ASC";
        try {
                pst = conn.prepareStatement(sql);
               ResultSet rs_item = pst.executeQuery();
                jCombo_Items.addItem("");
                  
        while(rs_item.next()){
                 S = rs_item.getString("description");
                jCombo_Items.addItem(S);
                itemMap.put(rs_item.getString("stock_id"), S);
                itemMap1.put(S, rs_item.getString("units"));
              }
             
        }catch (Exception e) {
           
            JOptionPane.showMessageDialog(this, "Error in connecitivity " +e);
        }
       
        
    }

Get Data From  it

  stock_name = (String) jCombo_Items.getSelectedItem();
           stock_id = getKeyForValue(stock_name,itemMap);
           unit = getValueForKey(stock_name,itemMap1);
         

No comments:

Post a Comment