This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes CachedRowSet.populate(Resultset rs , int StartRow ) Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "CachedRowSet.populate(Resultset rs , int StartRow ) Issue" Watch "CachedRowSet.populate(Resultset rs , int StartRow ) Issue" New topic
Author

CachedRowSet.populate(Resultset rs , int StartRow ) Issue

Neha k Agrawal
Greenhorn

Joined: Mar 25, 2008
Posts: 25
Hi All,
Thank you for stopping here. I am facing some weird issue with CachedRowSet.populate(Resultset rs , int StartRow ) method. I am using OracleCachedRowSet.


Suppose the cursor is on 3rd row in the ResultSet and I want to copy the 2nd row .

CachedRowSet.setPageSize(1);
CachedRowSet.populate(rs , 2) ;

So it should actually copy the 2nd row but unfortunately , it is copying the 3rd row. Can anyone please tell me what am I doing wrong here.
G krishna kumar
Greenhorn

Joined: Oct 10, 2012
Posts: 14
http://docs.oracle.com/javase/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html

10.0 Paging Data

refer here you will get the solution.


CachedRowSet.setPageSize(1);
CachedRowSet.populate(rs , 2) ;

When this code runs, crs will be populated with one row from rsHandle starting with the second row.

its working fine for me.

Neha k Agrawal
Greenhorn

Joined: Mar 25, 2008
Posts: 25
Thanks Krishna . But I have gone through this doc and I am setting the page size correctly. My issue is that populate method is not copying the rows from the startIndex which I am sending . If I am sending startIndex = 1 , it copies the data from row 2.

I have spent an entire day on this issue and I feel there is a bug with this method but I am surprised to see that no one has ever reported it .
G krishna kumar
Greenhorn

Joined: Oct 10, 2012
Posts: 14
can you post you code.
Neha k Agrawal
Greenhorn

Joined: Mar 25, 2008
Posts: 25
Please see the code below. Basically I am populating the CachedRowSet from CachedRowSet Only instead of Result set. But I think that shouldn't matter.

So "rs" has all the rows from my query and I want to group all the rows with same key and copy them in a new CachedRowSet.

For ex:- In the below data, first 3 rows have same key[a1] , so I want to club them and put into a new cachedRowSet. So PageSize would be 3 and startIndex would be 1
but for a2 there is only one record so pageSize would be 1.

But my issue is , even if I set the startIndex as 1 , it is copying the data from 2nd row.


id , name , address
a1 name1 india
a1 name2 india
a1 name3 india
a2 name4 india
a2 name5 india
a3 name6 india






G krishna kumar
Greenhorn

Joined: Oct 10, 2012
Posts: 14
boolean isNextRow = rs.next();

for checking weather the resultset object contains the record or not you can use


problem is that when checking rs.next() it is pointing towards the first record.
again in the inner loop you are doing rs.next() here it is pointing towards the second record instead of first.

regards
kumar
 
 
subject: CachedRowSet.populate(Resultset rs , int StartRow ) Issue