3

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);
1

2 Answers 2

5

After research I found following:

  1. Instead of withProcedureName() method withFunctionName() method should be used.
  2. Instead of execute() method use executeFunction() 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.

Sign up to request clarification or add additional context in comments.

Comments

0

Calling executeFunction on the call worked for me, while i had to keep ".withProcedureName(...)" as it was. Check out your updated code:

SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource)
     .withSchemaName("SCHMA")
     .withCatalogName("PKG_USER")
     .withProcedureName("get_user_by_term");
MapSqlParameterSource inParams = new MapSqlParameterSource()
     .addValue("inUserTerm ", userTermId );

Long returnVal = simpleJdbcCall.executeFunction(BigDecimal.class, inParams).longValue();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.