Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning a ResultSet?

 
Donna Reschke
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am debating whether or not to create a function that will return a ResultSet. Is this something that is acceptable or is it bad practice?
 
Tanel Alumae
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shouldn't be a problem as long as you are sure that you close the ResultSet after using it.
But, I think a better ways is to convert the ResultSet to a List or array of objects that encapsulate the data that is in the ResultSet and return that List (or array). That way, the client class does not have to care about the details of ResultSet closing and it even doesn't need to know that the data is coming from a relational database.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
things can get very messy if you start to throw ResultSets around, especially between classes or on high traffic applications. Your objective should be to minimize stress on the database, so you should have a "get in, and get out" type attitude. As mentioned above, store it in an object/collection that best suits your needs to process the results.
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic