cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP DBTech JDBC: Cannot convert SQL type TABLE to Java type java.lang.Object.

arungupta0374
Associate
Associate
0 Likes
2,308
My Procedure is something like :
PROCEDURE SAMPLE(
    IN EMP_DATA     COM_SAP_EMP,
    IN ID INTEGER,
    IN AGE INTEGER,
   OUT RESULT   TABLE("ABC" NVARCHAR(10),
                      "DEF" NVARCHAR(10),
                      "GHI" NVARCHAR(20))
) READS SQL DATA AS
BEGIN

I need to call it from my CAP Java project but couldn't 
find any, how can i get the result out of the execution of this procedure, 
as to get that we have to register the out parameter as below:

callableStatement.registerOutParameter("RESULT", Types.???);

Here I had tried with what all possible values of Types.__ available.

Accepted Solutions (0)

Answers (2)

Answers (2)

sunil_111k80
Discoverer

Hi Arun, Have you find any solution for this problem ?

Former Member
0 Likes

Hi everybody,

i managed to find a way, how to do it. Hope it will help somebody. So you need to set result type to  Types.OTHER and then set value to "null".
Than check in debugger the name of returned array (in my case it was "#result-set-1") and loop through it

SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
                .withProcedureName(ProcedureName.PROCEDURE_NAME)
                .declareParameters(new SqlParameter("FIRST", Types.VARCHAR),
                        new SqlParameter("SECOND", Types.VARCHAR),
                        new SqlParameter("RESULT", Types.OTHER));

        Map<String, Object> inParamMap = new HashMap<>();
        inParamMap.put("FIRST", "example");
        inParamMap.put("SECOND", "example2");
        inParamMap.put("RESULT", null);
        SqlParameterSource in = new MapSqlParameterSource(inParamMap);

        var simpleJdbcCallResult = simpleJdbcCall.execute(in);

        ArrayList<Map<String, Object>> result = (ArrayList<Map<String, Object>>) simpleJdbcCallResult
                .get("#result-set-1");
        for (Map<String, Object> resultRow : result) {
            var a = (Double) resultRow.get("RESULT_PARAM1");
            var b = (Double) resultRow.get("RESULT_PARAM2");
            ...
        }