• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JDBC exception question

 
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am practicing for the OCP exam, and I wrote the following, which combines bits I found on Youtube as well as from Mala Gupta's book:



The issue I encounter is that when I have the executeUpdate as it is in the code above, with it in between the ResultSet creation and processing of the ResultSet in the while loop, I get the following runtime exception:



However, if I move the executeUpdate statement to before the ResultSet is created, or to after the ResultSet while loop, I don't get this exception. In all cases, the table was created successfully. Can anyone please explain this?

Thank you.
 
author & internet detective
Posts: 39538
778
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ResultSet can only be used when the query was the most recent SQL run on that Statement. In your example, you do an executeUpdate() in between so it is gone.
 
John Freeman
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:The ResultSet can only be used when the query was the most recent SQL run on that Statement. In your example, you do an executeUpdate() in between so it is gone.



Thanks Jeanne!
 
I'm so happy! And I wish to make this tiny ad happy too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!