Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet can not print the first row

 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here's my code :


My Problem is that :
This code does not print the very first row.

How can I do that ?

Also the table is distorted..

Please help

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the documentation for ResultSet.next(). Not certain, but I think you are going to the first row when you call if (rs.next()) . . . and when you get to the while (rs.next()) . . . loop, you are going to the second row.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is right. Each time you call "rs.getNext()" you move the cursor down one row. That means on the first iteration of your loop, you'll be getting data out of the second row. Use a do-while loop instead.


(Alternatively, you could call "rs.beforeFirst()" after doing your initial check, but it's more fun to annoy the people who lay down the hate against poor, poor do-while.)
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it's more fun to annoy the people who lay down the hate against poor, poor do-while


I didnt know they existed
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote: . . . I didnt know they existed
You'd be surprised
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic