• Post Reply Bookmark Topic Watch Topic
  • New Topic

Combining Resultsets  RSS feed

 
Ann Maria
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we combine resultsets into a single resultset? If possible, how?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write a class yourself that implements interface ResultSet and that combines the data of two ResultSet objects.

What are you trying to achieve by combining two ResultSets?
 
Thomas Samimuthu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ann Maria:
Can we combine resultsets into a single resultset? If possible, how?


construct two dimensional object array(Object[][]) from the individual ResultSet and merge the tow arrays. Or you can use Collection.
keeping two different ResultSet is not a good idea becuase unless you close the ResultSet it still attached to the Connection. By the way you can modify your SQL to get everything in one single ResultSet probably you can use SQL JOIN.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ann Maria:
Can we combine resultsets into a single resultset? If possible, how?


We don't know how - why don't you tell us?
Here's a good start:

The rest will require you to define the term 'combine'.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Thomas meant to use the SQL term "UNION". Could a UNION solve your problem?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll toss out an ancient algorithm I learned when merging stacks of punch cards. This assumes data is sorted on some kind of key we can match between the two datasets:

Can you imagine your merge now? What do you do when a key is in one result set but not the other ... add it to the output set? What do you do when a key is in both input sets ... use data from one or the other or do they maybe have different columns?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would note that the original post was ten days ago, and Jesper's response asked the critical question: what are you trying to achieve? There's been no response since then. I would suggest that there's little point offering a bunch more questions and suggestions if she's not following up.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!