0

In my java code, I have multiple select statements running against a database. Each select returns a different resultset. Now I want to have all the result sets under one resultset & pass as the return object.

I want the result sets to be children of the final result being passed. How can I achieve this. I am new to Java. Please help.

In addition to the result sets from select, there are also some values in local variable that need to be passed back.

User3
  • 69
  • 1
  • 9
  • 1
    Is it an ok solution if you return a list of resultsets? – Pphoenix Jul 11 '14 at 12:28
  • 2
    Map might be even better. Though is it not feasible just to map resultset to objects and then create whatever structure you need? – Aubergine Jul 11 '14 at 12:32
  • 1
    In what means are the result-sets different? Different column-structure or column-names? Then you won't have much fun processing them as one result-set. If it's the same structure why not use `UNION` on database-level? – piet.t Jul 11 '14 at 12:41
  • The result sets are different with different columns. – User3 Jul 11 '14 at 12:56
  • This thread might be a possible answer [http://stackoverflow.com/questions/10797794/multiple-queries-executed-in-java-in-single-statement](http://stackoverflow.com/questions/10797794/multiple-queries-executed-in-java-in-single-statement) – lafarer Jul 11 '14 at 12:58

1 Answers1

0

This sounds like joining for me. If you do not modify data then you can use a join in your query and process each row after the values are returned.

If for some reason a join is not an option, then you can create a tree and add nodes at their appropriate position to achieve the hierarchy you want.

I cannot give you more information, as the only specified technology was Java and I do not know what database server are you using.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • I am using oracle database. I can not use join, as the result sets from the different select return different columns and data and they have to be returned back as such. Can you provide details on the tree option you mentioned. – User3 Jul 11 '14 at 12:55
  • @User3, you are mixing joins with union. Read this about joins in Oracle: http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm. As about the tree. You have a semantic hierarchy if I am not mistaken, so if there are tables T1 and T2, then T2 should be a child of T1 if and only if a T1 can have more T2 elements and there is nothing in between. For instance, let's consider you have tables like country, county and town. A country can have several counties and a county can have several towns. – Lajos Arpad Jul 11 '14 at 13:17
  • You can create a tree with an abstract node as root and the countries as the children of the root. Each county would be a child of its country and each city would be a child of its county. But I repeat, I believe you should have a few joins in your select to have a single request to the database server and when you get the result set you should build the tree data structure and return that. I would do that if I were you. – Lajos Arpad Jul 11 '14 at 13:19