• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JDBC exception question

 
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41415
854
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic