0

I have a set of java classes, and they have certain number of attributes, these attributes are being assigned values through SQL Queries which is run against a database, in certain classes all the attributes are not being fetched by a single SQL query, but multiple queries instead, so my current implementation is running these queries one after the other and working with multiple resultsets to initialize the java objects. I am looking for a better way to do this, please note that i am not the producer for the SQL database, i am just a consumer, so i don't have access to the schema of the tables.

kumarD
  • 574
  • 2
  • 9
  • 23

1 Answers1

0

The only thing you can do to avoid many ResulSet for one object is to refactor your queries into one. Of course if you don't have access to the schema this will not be easy to do.. But the producer of this db should be sensible to the performance that you can gain by executing one query instead of "multiples".

If you really cannot do anything for the queries then you can search for or build an utility to merge/decorate/compose many ResulSet in one class.

Anyway I don't see any problem of building one object from many ResulSet. The problem is more the reason why you cannot have one ResulSet.

gervais.b
  • 2,294
  • 2
  • 22
  • 46
  • building a single object from multiple result sets, is annoying because, it gets me through errors, like one of the column in the other resultset may be null, etc etc, hence looking for a better way to solve this. – kumarD Sep 20 '17 at 05:23
  • yes it is annoying, I agree but it happens. As previously said, the problem is that you have to use many queries for one object. Hope that you can solve it with one query. – gervais.b Sep 20 '17 at 07:04