簡體   English   中英

行中的結果集輸出將轉換為以逗號分隔的單個col輸出

[英]Resultset output in rows to be converted to single col output separated by comma

我正在嘗試編寫此Java過程,以單個逗號(而不是多行)分隔的col形式顯示此代碼的輸出。 在printOut部分中,我想將行中的所有輸出合並到每個用戶1 col。 我嘗試使用ArrayList arr = new ArrayList()和Set results = new HashSet(),這樣我就可以得到用逗號分隔的數組中的所有行值,如預期輸出所示。

         ResultSet group=(ResultSet)Groups.getFieldValue(USER_GROUP_RESULTSET);//Gets all the user groups for the user
        printOut("Groupscount:"+group.getRowCount()); //Counts the # of user groups user is assigned to for printing purpose only
        group.moveFirst();
        while(!group.isEof()) {  //For all the user groups,list the user name and another col with all user groups separated by comma instead of individual rows.
        String groupname1= group.getFieldValueString(USER_GROUP); // fetches the user group name in the string. Do i need to use array here?
        printOut(USER+";"+groupname1); // It displays the output row wise
        group.moveNext();

                }

實際輸出:
用戶1; XYZ
用戶1; ABC

預期輸出:User1; XYZ,ABC

您需要將printOut移到while循環之外

StringBuilder sb=new StringBuilder();
while(!group.isEof()) {
String groupname1=group.getFieldValueString(USER_GROUP);
sb.append(";"+groupname1);
group.moveNext();
}

printOut(USER+sb.toString());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM