• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem while viewing a ResultSet in JDBC

 
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now i m learning ResultSet types in java. Here, I've coded for viewing records in different ways.... At first i displayed the whole records which is in emp4 table and then i started to view these records in different manner(last,first,next) This is exactly what i am looking for but it won't display the all records which are presented in the emp4 table. See the First Program it doesn't work but if i documented the line 41(see this in Second Program) it just working awesome.... What's the problem ? is there any wrong with my code ???

CODE SAMPLE 1


Here, the code will works fine.....

CODE SAMPLE 2



OUTPUT
Displaying records for last row
ID : 5
GMAIL : naveen
YAHOO : naveenrockz

Displaying records for first row
ID : 1
GMAIL : vinothvino
YAHOO : vinothasd

Displaying records for next row
ID : 2
GMAIL : ajithvirje
YAHOO : ajith234


Please make me understand.....
error.png
[Thumbnail for error.png]
Records in the emp4 table
 
Sheriff
Posts: 28399
100
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both code samples look the same to me... perhaps you could check to see whether you posted what you meant to post? They could be different, but it's very hard for a reader to compare the two.

Anyway both of them should be throwing an exception at line 41, where you try to use data from a row when you haven't set a row yet. Was that what you meant when you said "doesn't work"? It would help in future if you explained in more detail what your problem was.
 
Ranch Hand
Posts: 34
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think on Code Sample 2, he meant to comment out line 41, but forgot to.

So Code Sample 1 won't work as explained - before you can use a ResultSet, you have to do a next() or last() or first() etc. As you haven't done any of these before line 41, you get an error as you have started using it.

If you want to show all the rows first, do a (while rs.next()) { ... }
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EDITED CODE
sorry i forgot to comment the line 41.... Here, is the program which I've documented at the line 41. Please help me

vinoth vino wrote: Now i m learning ResultSet types in java. Here, I've coded for viewing records in different ways.... At first i displayed the whole records which is in emp4 table and then i started to view these records in different manner(last,first,next) This is exactly what i am looking for but it won't display the all records which are presented in the emp4 table. See the First Program it doesn't work but if i documented the line 41(see this in Second Program) it just working awesome.... What's the problem ? is there any wrong with my code ???

CODE SAMPLE 1


Here, the code will works fine.....

CODE SAMPLE 2



OUTPUT
Displaying records for last row
ID : 5
GMAIL : naveen
YAHOO : naveenrockz

Displaying records for first row
ID : 1
GMAIL : vinothvino
YAHOO : vinothasd

Displaying records for next row
ID : 2
GMAIL : ajithvirje
YAHOO : ajith234


Please make me understand.....

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Both code samples look the same to me... perhaps you could check to see whether you posted what you meant to post? They could be different, but it's very hard for a reader to compare the two.

Anyway both of them should be throwing an exception at line 41, where you try to use data from a row when you haven't set a row yet. Was that what you meant when you said "doesn't work"? It would help in future if you explained in more detail what your problem was.


I'm Sorry!! I shouldn't have done like that.Please check it again... I've changed my code with comment.
 
Paul Clapham
Sheriff
Posts: 28399
100
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I can see John Smithonian has provided the right answer... does his answer work for you?
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Smithonian wrote:I think on Code Sample 2, he meant to comment out line 41, but forgot to.

So Code Sample 1 won't work as explained - before you can use a ResultSet, you have to do a next() or last() or first() etc. As you haven't done any of these before line 41, you get an error as you have started using it.

If you want to show all the rows first, do a (while rs.next()) { ... }


Thank you so much..... It works good

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:As far as I can see John Smithonian has provided the right answer... does his answer work for you?


Thanks for your efforts.... Now it works without any issue

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic