• 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

OCP 17 Study Guide - Practice Exam #1

 
Greenhorn
Posts: 25
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody!
This is question 14 from exam #1


Suppose that the table counts has five rows with the numbers 1 to 5. How many lines does this code print?




And that's the answer:

This code is tricky. While it does have two loops for the ResultSet, there is no call to the database in between. Therefore, the second call to setInt() is unused, and the second while loop does not iterate through any data. Only two lines are printed, making option C correct.


I can't understand why it says it prints two lines. For what I see the query is executed once and get just one line. So the first time rs.next() returns true and the result is printed, but the second time it returns false, and the second while loop is not executed.
 
Marco Olivi
Greenhorn
Posts: 25
3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it. "num>3", while I was reading "num==3"
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic