【发布时间】:2017-06-09 19:51:31
【问题描述】:
我见过很多从simpleJdbcCall.executeFunction 获取单个原始结果的示例。我需要知道如何访问一组结果。 execute 返回 Map。您必须将SqlOutParameter 提供给executeFunction 并告诉它要返回的类型。好吧,我将返回映射到MyCustomClass.class,它返回null。我知道该函数将返回 3 BIGINT out 参数值。
public class MyDao {
private final JdbcTemplate theTemplate;;
//@Autowired ctor
public long createCategory(final CategoryEntity category) {
final SimpleJdbcCall jdbcCall = getJdbcCall();
return mapResult(jdbcCall.executeFunction(MyResultEntity.class, fromEntity(category)));
}
private long mapResult(MyResultEntity result) {
return result.getOut_id();//FAIL
}
private SqlParameterSource fromEntity(final MyEntity category) {
Map<String,Object> params = new HashMap<>();
params.put("in_name", category.getName());
params.put("in_description", category.getDescription());
SqlParameterSource result = new MapSqlParameterSource(params);
return result;
}
private SimpleJdbcCall getJdbcCall() {
//I need the value returned by "out_id"
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(theTemplate)
.withSchemaName("mySchema")
.withFunctionName("my_function")
.declareParameters(
new SqlOutParameter("out_id", Types.BIGINT),
new SqlOutParameter("out_2", Types.BIGINT),
new SqlOutParameter("out_3", Types.BIGINT)
);
return jdbcCall;
}
}
【问题讨论】:
标签: java jdbc spring-jdbc