| Author |
ResultSet can not print the first row
|
Shounak Kundu
Ranch Hand
Joined: Jul 29, 2010
Posts: 60
|
|
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
|
Shounak
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
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
Bartender
Joined: Oct 01, 2001
Posts: 2542
|
|
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
Joined: Feb 24, 2006
Posts: 6588
|
|
but it's more fun to annoy the people who lay down the hate against poor, poor do-while
I didnt know they existed
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Deepak Bala wrote: . . . I didnt know they existed
You'd be surprised
|
 |
 |
|
|
subject: ResultSet can not print the first row
|
|
|