After validation of select combo box which I have selected and I am not able to insert it in my database. Tomcat gives following error:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
How is this caused and how can I solve it?
You will get this error when you call any of the
setXxx()methods onPreparedStatement, while the SQL query string does not have any placeholders?for this.For example this is wrong:
You need to fix the SQL query string accordingly to specify the placeholders.
Note the parameter index starts with
1and that you do not need to quote those placeholders like so:Otherwise you will still get the same exception, because the SQL parser will then interpret them as the actual string values and thus can’t find the placeholders anymore.
See also: