This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes Populating RowSet with another RowSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Populating RowSet with another RowSet" Watch "Populating RowSet with another RowSet" New topic
Author

Populating RowSet with another RowSet

Seb Castiaux
Greenhorn

Joined: Jul 22, 2002
Posts: 6
Hi,
I am working on a client/server querying application. I want to keep the entire result of query on the server and send blocks of this result to the client on demand.
Let's consider a RowSet (serverRS) of 100 elements and I want to send rows 21 to 40 to the client.
How can I populate a RowSet (clientRS) with those rows? Eliminating the first rows seems easy by calling serverRS.absolute(21) before calling clientRS.populate(serverRS) but I cannot find an easy way for the rows after row 40?
Can u help me?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Are you querying a database on the server? Or are you querying your own server implementation of some sort. Basically, I am not sure this question is about and belongs in the JDBC forum. If you could clarify what you are doing I may be able to find a better forum for this question or I will leave it here.


GenRocket - Experts at Building Test Data
Seb Castiaux
Greenhorn

Joined: Jul 22, 2002
Posts: 6
I am querying a database on the server and cache the obtained ResultSet. I would like to send this data to my client by blocks (on demand) as RowSet. My problem is to extract the block from the cached ResultSet and put it in the serializable RowSet that i send to the client.
Don't hesitate to ask for some clarifications if i am not making myself clear.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I think what you need to do is scrap the ResultSet all together and use the RowSet API in the JDBC spec. I am still not entirely clear on what you are trying to do. But to me it looks like you have an extra step.
Query the Database
Put data in RowSet
Send chucks of that RowSet to a client
So if this is accurate, I would ask why not allow the client to query the database and return what it needs?
BTW - Here is a tutorial on using the JDBC RowSet API (CachedRowSet, JDBCRowSet, WebRowSet). If I am way off track let me know.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I think this is the scenario that we are describing:
1) We extract data from a database and store the result in a CachedRowSet.
2) We want to send part of this RowSet to a client as a new RowSet object.
There may be several reasons that the client can not access the database directly. It could be a firewall issue or simply a size issue.
The question is, can I create a new RowSet from the middle of an existing RowSet.
I don't see any straight forward way to do this from the documentation. In fact, although using absolute(21) works, since this is not documented I would be nervous about relying on it. It just happens that the implementation does not reset the ResultSet to the beginning but I see nothing that would make me think that this is guaranteed in all implementations.
You could create a new RowSet using populate() and then delete the unwanted rows. Or you could create a new empty RowSet, copy the MetaData over, and then insert rows. Neither is a very pretty solution.
Perhaps the easiest way would be to write your own implementation, extending CachedRowSetImpl.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ok, if Tom is correct in his assumptions of the problem, it makes sense now. Thanks for clearing that up. I would be interested in learning how you decided to solve this problem Seb.
Seb Castiaux
Greenhorn

Joined: Jul 22, 2002
Posts: 6
Thanks for clarifications Tom, your assumptions are totaly right. The reason is only a size and network traffic problem. I will let you know how I manage to solve this problem.
Thanks
 
GeeCON Prague 2014
 
subject: Populating RowSet with another RowSet