如何从Java中的哈希表中检索密钥

我是Java的新手,因此我试图找到一种从Hashtable检索密钥的方法。编写下面的代码来从数据库中检索值,并使用存储过程以键/值对格式将其插入到Hashtable中。

private Hashtable loadRspCodeMappingFromDB(String node_name) 
throws SQLException
{ 
    //TO DO:
    // Take a look at the SDK user guide -> Programming conventions -> Database access using JDBC.
    // Use the stored procedure you've created to fill a Hashtable to return.

    // Two events have been created in events.er for your use:
    // RspCodeMappingLoaded, and
    // ErrorReadingRspCodeMapping

   Hashtable resp_mapping_table = new Hashtable();  
   Connection cn          = null;
   CallableStatement stmt = null;
   ResultSet rs           = null;
   try
   {
      cn = JdbcManager.getDefaultConnection();

      stmt = cn.prepareCall("{call samplenid_get_rsp_map(?)}");
      stmt.setString(1, node_name);
      rs = stmt.executeQuery();

      while(rs.next()){

      tm_rsp_code = rs.getString(1);
      Interchange_rsp_code = rs.getString(2);

      resp_mapping_table.put(tm_rsp_code, Interchange_rsp_code);
      }

      JdbcManager.commit(cn, stmt, rs);
   }
   finally
   {
      JdbcManager.cleanup(cn, stmt, rs);
   }

    return resp_mapping_table;
}

编写第二个代码块是为了从Hashtable检索映射的键并将其包含在事务消息中,但不幸的是,我遇到此错误:“无法从元素类型Object转换为Map.Entry。

public Action processMsgFromRemote(AIntegrationDriverEnvironment env,Iso8583Post msg) 
throws XPostilion, SQLException
{
    //TO DO:
    // 1. Check if the message is a response message
    // 2.1 Check the integration driver environment to discover the sink node name
    // 2.2 If the rsp code mapping has not yet been loaded, load rsp code 
    //       mapping from table now. Use the loadRspCodeMappingFromDB() method
    //       below.
    //  3.1 Check if a mapping exists
    // 3.2 If a mapping exists, set the value to transaction manager
    // 4. Return the action with the message to Transaction Manager


    Action action = new Action();

    boolean check_msg_type = Iso8583Post.MsgType.isResponse(msg.getMsgType());

    if(check_msg_type){

        String node_name = env.getSinkNodeName();

        if( rsp_map  == null)
        {
             rsp_map  = loadRspCodeMappingFromDB(node_name);
        }
        else{
        String rsp_code_from_cache_loader = (String) rsp_map.get(tm_rsp_code);
        String rsp_code_msg_from_interchange = msg.getField(Iso8583.Bit._039_RSP_CODE);

        if(rsp_code_from_cache_loader.equals(rsp_code_msg_from_interchange)){
            for(Map.Entry entry:  rsp_map.entrySet()){
                if(rsp_code_from_cache_loader.equals(entry.getValue())){
                    tm_rsp_code = (String) entry.getKey();
                    break;
                }
            }
        }
        }
    }
    action.putMsgToTranmgr(msg);
  return action;    
}

我想知道该错误的解决方案。我该如何解决?

评论