2
votes

I have 10 parameters set in the statement with the question marks and provided 10 associated values. At execution, it’s throwing this error “org.postgresql.util.PSQLException: No value specified for parameter 11.” I’m having a similar issue with another table where it’s also asking for an out of range parameter. I can manually run the query against PostGres without any problem. Please see log below, thanks in advance.

[DBOperations]:INSERT INTO product.SHIB_RP_MD_PROVIDER(RP_MD_PROVIDER_ID,MD_PROVIDER_TYPE_ID,MD_ID,SRC_ORG_ID,MD_NAME,MD_DESC,PARENT_RP_MD_PROVIDER_ID,LAST_UPDATE_USER,LAST_UPDATE_DATE,SYSTEM_IND,ORG_ID) VALUES (?,?,?,?,?,?,?,?,date_trunc('second' , now()),?,?)

[DBOperations]:No value specified for parameter 11. org.postgresql.util.PSQLException: No value specified for parameter 11.

[DBOperations] - Index 1 - Value 10042
[DBOperations] - Index 2 - Value 4
[DBOperations] - Index 3 - Value aa
[DBOperations] - Index 4 - Value 2
[DBOperations] - Index 5 - Value aa
[DBOperations] - Index 6 - Value null
[DBOperations] - Index 7 - Value 0
[DBOperations] - Index 8 - Value 1234
[DBOperations] - Index 9 - Value 0
[DBOperations] - Index 10 - Value 2
2
you actually have 11 parameters. did you put in an extra one by accident? - Reimeus

2 Answers

2
votes
   INSERT INTO dah53idm.SHIB_RP_MD_PROVIDER(RP_MD_PROVIDER_ID,MD_PROVIDER_TYPE_ID,
    MD_ID,SRC_ORG_ID,MD_NAME,
    MD_DESC,PARENT_RP_MD_PROVIDER_ID,
    LAST_UPDATE_USERID,
    LAST_UPDATE_DATE,
    SYSTEM_IND,ORG_ID) VALUES (?,?,?,?,?,?,?,?,date_trunc('second' , now()),?,?)

well answer is pretty obvious . but i'll point it out anyway, you have 11 question marks which means you are supposed to add 11 values to execute the query but in your code you are adding only 10 , hence the exception "no value specified for 11"

0
votes

assign all the parameters to the values properly

for (User user : users) {
    System.out.println("Inserting Data for Userr name" + user.getName());
    jdbcTemplate.update("insert into USERR(Id,Name,Dept,Salary) 
    values(?,?,?,?)",
    preparedStatement -> {
        preparedStatement.setLong(1,user.getId());
        preparedStatement.setString(2, user.getName());
        preparedStatement.setString(3, user.getDept());
        preparedStatement.setLong(4, user.getSalary());

    });