java.sql.SQLException: Wrong number of parameters: expected 0, was given 5 Query:

Viewed 29

I am facing issue during the database query call and receiving below mentioned error. Facing this issue when running the code in local. Code base is setup in Java 1.7 and Ant Build.

ERROR: java.sql.SQLException: Wrong number of parameters: expected 0, was given 5 Query:

{call dbo.SaveTest(?,?,?,?,?)} Parameters: [value1, value2, value3, value4, value5]

Code:

QueryRunner run = new QueryRunner(ContextListener.getDataSource());
BigDecimal result = run.query("{call dbo.SaveTest(?,?,?,?,?)}", new ScalarHandler<BigDecimal>(), mapping2, 
mapping3, mapping4, mapping5);

Any help is appreciated on the issue.

1 Answers

You have to call execute not query:

execute(String sql, ResultSetHandler rsh, Object... params) Execute an SQL statement, including a stored procedure call, which returns one or more result sets.

BigDecimal result = run.execute("{call dbo.SaveTest(?,?,?,?,?)}", new ScalarHandler<BigDecimal>(), mapping2, 
mapping3, mapping4, mapping5);

For more information read the javadoc:

https://commons.apache.org/proper/commons-dbutils/apidocs/org/apache/commons/dbutils/QueryRunner.html
Related