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.
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.
Loudly announcing something is true and finding out you're wrong makes you feel foolish.
Finding out you're wrong and refusing to admit it makes you LOOK foolish.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop