我正在研究一段具有 Hashmap 的代码。这个 hashmap 有一个字符串作为键,一个数组列表作为值。我使用 DQL 获取的值填充 arraylist。我为许多用户提供了三个属性。然后将值放入哈希图中。我想要的是迭代 Hashmap 并为 1 个用户获取一组 3 个属性。让我提供下面的代码
package com;
import java.io.IOException;
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;
import xtrim.util.i;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;
public class Adlookup {
IDfSessionManager sessionMrg = null;
IDfSession session=null;
IDfClient dfclient = null;
IDfClientX clientX = new DfClientX();
IDfCollection total = null;
int j;
int flag = 0;
WriteToExcel ex = new WriteToExcel();
public void LookupReport(String docbaseName, String username, String password) throws DfException, IOException
{
dfclient = clientX.getLocalClient();
String Docbase = docbaseName;
IDfLoginInfo loginInfo = new DfLoginInfo();
loginInfo.setUser(username);
loginInfo.setPassword(password);
sessionMrg = dfclient.newSessionManager();
sessionMrg.setIdentity(Docbase, loginInfo);
session = sessionMrg.getSession(Docbase);
System.out.println("connection created for adlookup");
String query = Getquery();
IDfQuery dql = new DfQuery();
dql.setDQL(query);
total = dql.execute(session, IDfQuery.DF_EXEC_QUERY);
System.out.println("all good for lookup");
//String[] columnNames = new String[] { "User Name","User Login Name","Email"};
List<String> lstValues = new ArrayList<String>();
Map<Integer, ArrayList<String>> myMap = new HashMap<Integer, ArrayList<String>>();
while (total.next())
{
lstValues.add(total.getString("uname")+","+total.getString("loginname")+","+total.getString("uadd"));
myMap.put(flag, (ArrayList<String>) lstValues);
flag++;
System.out.println("Flag value: " +flag);
// lstValues.clear();
}
Set setofKeys = myMap.keySet();
Iterator itr = setofKeys.iterator();
while(itr.hasNext())
{
Integer key = (Integer) itr.next();
ArrayList<String> value = myMap.get(key);
System.out.println("\nResult :"+value);
}
}
private String Getquery() {
// TODO Auto-generated method stub
String query = "select user_name as uname, user_login_name as loginname, user_address as uadd from dm_user dmu, dm_dbo.MV_V_MIDAS_MERCK_PRSN1 dma where upper(dmu.user_login_name)=upper(dma.isid) and dmu.user_state=0 and directory_display_ind='I'";
return query;
}
}
我得到这样的输出
Result :
[Sayre,Joseph,sayrej,joseph.sayre@abc.com, Kapoor,Rohit,kapoorro,rohit.kapoor@abc.com, Pineiros-Vallejo, Miguel,pineirom,rajendra.baxi@abc.com]
Result :[Sayre,Joseph,sayrej,joseph.sayre@abc.com, Kapoor,Rohit,kapoorro,rohit.kapoor@abc.com, Pineiros-Vallejo, Miguel,pineirom,rajendra.baxi@abc.com]
Result :[Sayre,Joseph,sayrej,joseph.sayre@abc.com, Kapoor,Rohit,kapoorro,rohit.kapoor@abc.com, Pineiros-Vallejo, Miguel,pineirom,rajendra.baxi@abc.com]
但我想要这样的东西:
Result : Sayre,Joseph,sayrej,joseph.sayre@abc.com
Result : Kapoor,Rohit,kapoorro,rohit.kapoor@abc.com
Result : Pineiros-Vallejo, Miguel,pineirom,rajendra.baxi@abc.com
我还需要在 excelsheet 中打印这些值。
任何形式的帮助将不胜感激。