groovy script / java code to get distinct users from resultset -


hi run simple select query in oracle on table , resultset. select username, responsibility, project mytable.
resultset contains user details. there multiple rows returned each username different values responsibility , project. want list of lists resultset has 1 list per username , distinct values concatenated in comma seperated string.
if sam has multiple entries in resultset output of operation should give me:

userlist = ["sam", "responsibility1,responsibility2,responsibility3...", "dept1,dept2,dept3.."], [some other user], [and on..] 

later write csv file.
cannot in query compatibility reasons, have support multiple databases, versions in future.
how do in java or groovy?

thanks

java quite easy. need class model each user. need map of username user. each user contains list of responsibility , list of departments. iterate resultset, find user map on each row , add responsibility , department user

do need code or enough?

hth

edit: here's java starting code: (not checked syntax or mistakes ;] )

public class user {     private final list<string> responsibility = new arraylist<string>();     private final list<string> department = new arraylist<string>();      ...standard getters , setters }  // code read public void executeread() {      ... obtain resultset somehow here      map<string, user> usernametouser = new hashmap<string, user>():     while (rs.next) {         string username = rs.getstring("username");         user user = usernametouser.get(username);         if (user == null) {             user = new user(); // create , remember user first time see them             usernametouser.put(username, user);         }         string responsiblity = rs.getstring("responsiblity");         string department = rs.getstring("department");         user.addresponsibility(responsibility);         user.adddepartment(department);     }     rs.close();      // have data structure of users in memory can output     // in whichever format e.g. html, csv, etc     // best step in totally separate place can     // switched out different output format in future. } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -