• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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: 39339
755
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!