ResultSet vs RowSet: Which one to choose and when?

Viewed 24599

So I'm aware of some relative differences i.e., the ResultSet has an 'open connection' to the database whereas a RowSet works in a 'disconnected' fashion.

But that's pretty much what I understand (may be incorrect):

My question is then this - under what circumstances is one preferable over the other? What are each of their strengths/weaknesses?

  • From what I feel a RowSet, working in disconnected mode especially for "read-only" queries, would have better performance in a highly concurrent system. Is that correct? If that's the case is it safe to say RowSet is always preferable to ResultSet for readonly queries?

  • If I'm correct iterating over the RowSet doesn't throw SQL Exceptions, but is that a benefit? The other being that RowSet is serializable. But my concern is primarily from a performance perspective what would be the choice?

  • But does it even matter for read-write queries?? Can you sync the ResultSet back to the DB? (I'm not sure if that's possible (It may be and I just can't recollect or google it well enough :) It's been a while with raw JDBC...

Any ideas? There are some missing gaps in my knowledge as is evident :)

The reason I ask is I'd like to choose between implementing Spring-JDBC's ResultSetExtractor Interface versus return an SqlRowSet when processing some data. This question just got me curious to how to decide what to choose when, other than tossing a coin :)

2 Answers
Related