Getting return value from oracle function using SimpleJdbcCall
10,395
After research I found following:
- Instead of
withProcedureName()
methodwithFunctionName()
method should be used. - Instead of
execute()
method useexecuteFunction()
with return type parameter.
So complete code be like
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource)
.withSchemaName("SCHMA").withCatalogName("PKG_USER")
.withFunctionName("get_user_by_term");
Map<String, Object> inParamMap = new HashMap<String, Object>();
inParamMap.put("inUserTerm ", userTermId );
SqlParameterSource in = new MapSqlParameterSource(inParamMap);
Long userId = simpleJdbcCall.executeFunction(BigDecimal.class, in).longValue();
Hope this will help others too.
Related videos on Youtube
Comments
-
αƞjiβ almost 2 years
I have Oracle function defined as:
function get_user_by_term (inUserTerm number) return number;
Now I wan to call this function using Spring SimpleJdbCCall but not sure how I can read return value since I don't have out param in function. I can't change the Oracle function code.
Code I have so far in Java is:
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource) .withSchemaName("SCHMA").withCatalogName("PKG_USER") .withProcedureName("get_user_by_term"); Map<String, Object> inParamMap = new HashMap<String, Object>(); inParamMap.put("inUserTerm ", userTermId ); SqlParameterSource in = new MapSqlParameterSource(inParamMap); simpleJdbcCall.execute(in);
-
cybersoft over 5 yearsSpring Documentation covers it here: 3.5.8. Calling a stored function using SimpleJdbcCall
-