// 调用有返回值的存储过程
String resultList = jdbcTemplate.execute(
"CALL MES_RESET_SN_STATUS_SP(?,?,?,?,?,?,?)",
(CallableStatementCallback<String>) callableStatement -> {
callableStatement.setString(1, productSn);
callableStatement.setString(2, "0");
callableStatement.setString(3, "");
callableStatement.setString(4, companyId);
callableStatement.setString(5, operator);
callableStatement.setString(6, stdGroupId);
// ... 设置更多参数
// 注册返回参数
callableStatement.registerOutParameter(7, java.sql.Types.VARCHAR);
// 执行存储过程
callableStatement.execute();
// 获取输出参数
String outputParam = callableStatement.getString(7);
return outputParam;
});
// 调用有返回值的存储过程
List<Map<String, Object>> resultList = jdbcTemplate.execute(
"CALL your_procedure_name_with_output(?, ?)",
(CallableStatementCallback<List<Map<String, Object>>>) callableStatement -> {
callableStatement.setString(1, "param1");
callableStatement.setInt(2, 123);
// ... 设置更多参数
// 注册返回参数
callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
// 执行存储过程
callableStatement.execute();
// 获取输出参数
String outputParam = callableStatement.getString(3);
// 获取存储过程返回的结果集
ResultSet rs = callableStatement.getResultSet();
RowMapper<Map<String, Object>> rowMapper = new ColumnMapRowMapper();
List<Map<String, Object>> list = new ArrayList<>();
while (rs.next()) {
list.add(rowMapper.mapRow(rs, 0));
}
return list;
});
java 利用jdbc调用存储过程 并且获取返回值
于 2024-12-24 17:49:30 首次发布