I have an Insert query that puts some data into several columns:
INSERT INTO table (a,b,c,d,e,f) VALUES (?,?,?,?,?,?);
I have a script that parses some documents and based on some tags it adds parameters to prepared statement. Usually all the parameters are set, however sometimes one or two fields are missing in the document. I have default values set for all the fields in the table, but they are not used. I get an exception:
java.sql.SQLException: No value specified for parameter 1
Is there a way to populate empty parameters automatically? Can I get a list of parameter ids that were not set, so that I can set them to empty corresponding data types?
Just set all the parameters to suitable default values. Then overwrite them with the "real" values as you find them in your input.
Note that if some of your columns are primary keys, you can't usefully use default values for those - unless you autogenerate them (e.g. random GUIDs).
See more on this question at Stackoverflow