• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

java.sql.SQLException: No value specified for parameter

 
Ranch Hand
Posts: 325
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have an servlet method that insert data in mysql table without problem now I'm trying to use "if exists" to insert or update the same parameters but I'm receiving an error "java.sql.SQLException: No value specified for parameter 87" the problem is that I don't have 87 parameter, I believe that my problem is my structure of string into the method but I can't see where is the error.
My method:

Thanks in advance.
 
Saloon Keeper
Posts: 6995
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ugh, what nightmarish code. Have you considered using JPA?

It looks like you are not setting the parameters in lines 5 and 7.
 
Saloon Keeper
Posts: 23774
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Ugh, what nightmarish code. Have you considered using JPA?



Agreed. And you're evidently not using Oracle, since their idea of an error message for something like that would simply say something like "invalid/missing parameter" and let you figure out which one it was. I do not miss those days.

The "?" replacements are numbered from the beginning of the statement template and it doesn't matter which clause they appear in, the count starts at 1 and proceeds upwards from there for the entire statement, not clause-by-clause.

I don't really recommend that you even bother with the existence test. Just let it throw an exception if the record doesn't exist. It's probably going to be less overhead anyway. And the joyous thing about SQL is that if you wanted INSERT OR REPLACE as an option, strict SQL doesn't permit that so you have to repeat all the code in INSERT form. A pox upon Codd and Date that they made it impossible to simply replace the verb and use the same predicate! You have to replicate the same basic statement in INSERT form, meaning twice the opportunities to screw up! Which is another argument in favor of JPA.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic