• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ResultSet can not print the first row

 
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 79153
377
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote: . . . I didnt know they existed

You'd be surprised
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic