I am trying to implement following tutorial https://www.tutorialspoint.com/spring/calling_stored_procedure.htm for simplejdbccall with postgres (need to migrate existing application from Oracle to Postgres which using simplejdbccall) but getting following exception
INFO: Unable to locate the corresponding parameter value for 'in_id' within the parameter values provided: [inID]
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: Required input parameter 'in_id' is missing
I am using following code to pull information:
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
// this.jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("getRecord");
this.jdbcCall = new SimpleJdbcCall(dataSource).withCatalogName("public").withFunctionName("getrecord1");
}
public Student getStudent(Integer id) {
//SqlParameterSource in = new MapSqlParameterSource().addValue("in_id", id);
System.out.println("----In getStudent-----"+id );
SqlParameterSource in = new MapSqlParameterSource().addValue("inID", id);
/* SqlParameterSource in = new MapSqlParameterSource().addValue("id", id, Types.INTEGER)
.addValue("name",Types.VARCHAR)
.addValue("age", Types.INTEGER);
*/
Map<String, Object> out = jdbcCall.execute(in);
Student student = new Student();
student.setId(id);
student.setName((String) out.get("out_name"));
student.setAge((Integer) out.get("out_age"));
return student;
}
and I have following function in postgres database:
CREATE function getrecord1 (in_id INTEGER, OUT out_name character,
OUT out_age Integer)
as
$$SELECT name, age from student where id=in_id$$
LANGUAGE sql VOLATILE
COST 100;
I have tried Receiving Message Unable to locate the Corresponding Parameter when calling Stored Procedure but using below code as well I am getting issue
SqlParameterSource in = new MapSqlParameterSource().addValue("id", id, Types.INTEGER)
.addValue("name",Types.VARCHAR)
.addValue("age", Types.INTEGER);