• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Combining Resultsets

 
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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?
 
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.
 
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'.
 
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?
 
(instanceof Sidekick)
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?
 
Wanderer
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.
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic