• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

very simple resultset question

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just asking this because I have looked around and have not been able to find an answer. How would I pass the resultset i created in my DAO to another class using my DAO object called daosam. Any response is appreciated. Thank you.

EDIT: whenever i search around i generally just come across passing it to another array or something else. It may be that i have worded it incorrectly. Is this so?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that it is not good programming to pass the resultset but instead to use entity manager. However, whenever I try to find an idea of how to get started, including the oracle docs, there never appears to be much relevance to JDBC. I am told, however, that resultsets and statements were only worthwhile with J2EE?
 
Lukas Eder
Ranch Hand
Posts: 49
5
Java Oracle Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to understand that a JDBC ResultSet is a very stateful and "resourceful" object. When you fetch a ResultSet in one DAO and pass it somewhere else, it is very hard to track its state correctly, i.e. to correctly:

  • ... assert that it is at the correct row
  • ... avoid concurrent access to it
  • ... close it when all consumers are finished with it


  • So there are two options:

  • Either, the consumer of your ResultSet is not broadly reused, i.e. it is only used by your daosam DAO. Then you might not break encapsulation and can just pass a ResultSet to a method
  • If your ResultSet consumer is more globally reused, you're better off unloading the JDBC ResultSet into a purely in-memory data structure (e.g. a List) and pass that to the consumer
  •  
    Sujeeth Pakala
    Ranch Hand
    Posts: 104
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Samuel,

    You are mis-using cohesiveness of DAO Object ;-)

    DAO, in general, is meant to do CRUD operations on external resource. JDBC ResultSet is synchronized with external resource, database in your case and ment to use in DAO class only and not to pass it to other (Service) classes.

    However, the data in ResultSet can be dumped in Domain object (usually POJO) and pass it to required object.

    BTW, why do you want to pass ResultSet to other object ?
     
    Samuel Bird
    Ranch Hand
    Posts: 96
    Eclipse IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Im sorry. I forgot to update this thread. It has been solved. I am no longer passing it.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic