Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple out parameters in SimpleJdbcCall

In Java spring boot framework,trying to consume the Store procedure using the following method

 jdbcTemplate.setDataSource(dataSource);

       SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
                                           .withSchemaName("abc")
                                           .withFunctionName("proname")
                                           .addDeclaredParameter(new
 SqlOutParameter("",""));
        Map<String, Object> map= new HashMap<>();
         map.put("a",a);
        map.put("b",b);
        map.put("c",c);
        map.put("d",d);

 SqlParameterSource in = new MapSqlParameterSource(map);
 Map<String, Object> out = simpleJdbcCall.execute(in);

but my procedure also has out parameters here is my procedure

function proname(z varchar2,
                                            a varchar2,
                                            b varchar2,
                                            c varchar2,
                                            d in out number,
                                            e out number,
                                            f out varchar2,
                                            g out varchar2)

the procedure also has out parameters as one can see in above code, Question is how can I mention multiple out parameters(Note Multiple ) in Simple JDBC Call????

like image 317
K Guru Avatar asked Nov 07 '22 06:11

K Guru


1 Answers

I tried like following and it works:

jdbcTemplate.execute((CallableStatementCreator) con -> {
        con = con.unwrap(OracleConnection.class);
        CallableStatement cs = con.prepareCall("{ ? = call usr.abc.proname(?,?,?,?,?,?,?) }");
        cs.registerOutParameter(1, OracleType.NUMBER);
        cs.setString(2, "a");
        cs.setString(3, "b");
        cs.setString(4, "c");
        cs.registerOutParameter(4, OracleType.NUMBER);
        cs.registerOutParameter(5, OracleType.NUMBER);
        cs.registerOutParameter(6, OracleType.VARCHAR);
        cs.registerOutParameter(7, OracleType.VARCHAR);
        return cs;
    }, (CallableStatementCallback<MyModel>) cs -> {
        cs.execute();
        return new MyModel(cs.getInt(1),
                           cs.getInt(4),
                           cs.getInt(5),
                           cs.getString(6),
                           cs.getString(7));
    });
like image 161
Ulphat Avatar answered Nov 14 '22 21:11

Ulphat