JdbcTemplate调用存储过程调用

问题描述 投票:0回答:1

我知道这很容易使用JdbcTemplate调用存储过程,但是这里的情况有所不同。我想调用一个不返回任何东西的存储过程函数。我尝试了以下代码,但工作正常,但我们无论如何都没有使用RowCountCallbackHandler,这很浪费

jdbcTemplate.query("select * from status_update(?) ",
                new Object[]{statusId},
                new int[]{Types.INTEGER}, new RowCountCallbackHandler());

我正在寻找的是类似下面的内容,显然不可用

jdbcTemplate.query("select * from status_update(?) ",
                new Object[]{statusId},
                new int[]{Types.INTEGER});

我想知道是否缺少使用JdbcTemplate执行无效存储过程的任何其他方法

stored-procedures java-8 jdbctemplate
1个回答
0
投票

您可以使用SimpleJdbcCall类。这使execute()方法过载,其中一种方法可以满足您的需要。

SimpleJdbcCall spCall = new SimpleJdbcCall(yourJdbcTemplate);
spCall.withProcedureName(SP_NAME);
spcall.execute(inParamsAsMap);

这将执行执行。如果您的SP具有输出参数,则可以执行以下操作。

Map<String, Object> output = spcall.execute(inParamsAsMap);

Doc link

© www.soinside.com 2019 - 2024. All rights reserved.