Java 在多个值之间检查

Java 在多个值之间检查,java,resultset,Java,Resultset,我将以下结果作为resultset的一部分 Name Dept John IT Mike IT Cathy CS Julie CS Aria Electronics Shann Electronics 姓名部门 约翰 迈克 凯西CS 朱莉CS 阿里亚电子 尚恩电子 我应该能够分开的部门为基础的结果集,并把结果在地图上。继迈克之后,部门发生了变化,因此我应该把约翰和迈克放在地图上。然后凯西和朱莉在地图上等等。我该怎么做 public void loadMap(ResultSet inputRes

我将以下结果作为resultset的一部分

Name Dept John IT Mike IT Cathy CS Julie CS Aria Electronics Shann Electronics 姓名部门 约翰 迈克 凯西CS 朱莉CS 阿里亚电子 尚恩电子 我应该能够分开的部门为基础的结果集,并把结果在地图上。继迈克之后,部门发生了变化,因此我应该把约翰和迈克放在地图上。然后凯西和朱莉在地图上等等。我该怎么做

public void loadMap(ResultSet inputResultSet, MbGlobalMap inputTranslationObjMap) throws Exception {

    String key = "";
    List < dept > list = new ArrayList < dept > ();

    while (inputResultSet.next()) {
        String name = inputResultSet.getString(1);
        String key = inputResultSet.getString(2);
        dept d1 = new dept(name, key);
        list.add(d1);
    }

    if (inputTranslationObjMap.containsKey(key)) {
        inputTranslationObjMap.update(key, list);
    } else {
        inputTranslationObjMap.put(key, list);
    }
}
public void loadMap(ResultSet inputResultSet,MbGlobalMap inputtransationobjmap)引发异常{
字符串键=”;
ListList=newarraylist();
while(inputResultSet.next()){
字符串名称=inputResultSet.getString(1);
String key=inputResultSet.getString(2);
部门d1=新部门(名称、关键字);
列表。添加(d1);
}
if(输入TranslationObjMap.containsKey(键)){
输入TranslationObjMap.update(键,列表);
}否则{
inputTranslationObjMap.put(键、列表);
}
}

试试这样的方法-

public void loadMap(ResultSet inputResultSet,
        MbGlobalMap inputTranslationObjMap) throws Exception {
    // String key = "";
    List<dept> list = null;
    while (inputResultSet.next()) {
        String name = inputResultSet.getString(1);
        String key = inputResultSet.getString(2);
        // first check if the map has a list already.
        if (inputTranslationObjMap.containsKey(key)) {
            list = inputTranslationObjMap.get(key);
        } else {
            // No... add a new list to the map.
            list = new ArrayList<dept>();
            inputTranslationObjMap.put(key, list);
        }
        dept d1 = new dept(name, key);
        list.add(d1);
    }
}
public void loadMap(结果集inputResultSet,
MbGlobalMap inputTranslationObjMap)引发异常{
//字符串键=”;
List=null;
while(inputResultSet.next()){
字符串名称=inputResultSet.getString(1);
String key=inputResultSet.getString(2);
//首先检查地图是否已经有列表。
if(输入TranslationObjMap.containsKey(键)){
list=inputTranslationObjMap.get(键);
}否则{
//否…将新列表添加到地图。
列表=新的ArrayList();
inputTranslationObjMap.put(键、列表);
}
部门d1=新部门(名称、关键字);
列表。添加(d1);
}
}

Post your code,英语是一种糟糕的编程语言。@elliotfrisch
true
。public void loadMap(ResultSet-inputResultSet,MbGlobalMap-inputresationobjmap)抛出异常{String key=”“;List List List=new ArrayList();而(inputResultSet.next()){String name=inputResultSet.getString(1);String key=inputResultSet.getString(2);dept d1=new dept(name,key);list.add(d1);}if(inputTranslationObjMap.containsKey)){inputTranslationObjMap.update(key,list);}else{inputTranslationObjMap.put(key,list);}}不在这里,请编辑您的问题。非常感谢。它有效:-)