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

incorrect results returning from my DB

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Im working with a small database for a simple enough quiz servlet program, i have the db working ok, it just prints out questions, im also using the DB to store the row of a random questions so that i can look up the correct answers between servlet instances.(this could be the complete wrong way to approach the problem, but it seems to work ok).my only problem is when i try to retrieve the row of the answer, im using microsoft access and i can see from the access program that its storing the correct question row as an int, but when i try to retrieve it im getting an error saying its a boolean which seems unusual since its storing correctly in the database.

this is from my checkAnswer servlet where im attempting to retrieve the answerRow, and its giving an invalid type of boolean.


any help would be much appreciated!

Go Raibh Maith Agat!


 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
resultset.next() tells you if there are any more rows in the result set.
Remember a result set can contain many columns for a single row, and lots of rows.

.
this page has a full example of how to use result sets.

http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
 
Brendan Cregan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:resultset.next() tells you if there are any more rows in the result set.
Remember a result set can contain many columns for a single row, and lots of rows.

.
this page has a full example of how to use result sets.

http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html



thanks Wendy, i have implemented this


but the problem is i need to read the value outside of the while loop, is there any other way to implement the answerRow.getInt() without the while()?

Thanks

Brendan
 
Marshal
Posts: 28425
102
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
It isn't the loop which is the problem. The problem is that you declared the answerRow variable inside the loop, thus restricting its scope so that it is only visible to code inside the loop. Since you want it to be visible outside the loop, then you have to declare it outside the loop.

Don't confuse declaring the variable (int answerRow) with assigning a value to it (answerRow = answerID.getInt(1)). You can do those two things separately, and in this case you should. Declare the variable outside (before) the loop, assign it the value inside the loop.
 
Brendan Cregan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:It isn't the loop which is the problem. The problem is that you declared the answerRow variable inside the loop, thus restricting its scope so that it is only visible to code inside the loop. Since you want it to be visible outside the loop, then you have to declare it outside the loop.

Don't confuse declaring the variable (int answerRow) with assigning a value to it (answerRow = answerID.getInt(1)). You can do those two things separately, and in this case you should. Declare the variable outside (before) the loop, assign it the value inside the loop.



thanks , I did understand the problem, but didnt know that declaring it ouside the loop was the solution!
Thanks Paul!

Brendan
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as you are only expecting 1 row you could do:
 
reply
    Bookmark Topic Watch Topic
  • New Topic