存储过程将多个表返回到spring jdbc模板

Iam使用JdbcTemplate从我的Spring DAO类调用存储过程。 我的问题是,存储过程返回多个表。 有没有办法使用Spring JdbcTemplate访问多个表。

如果我使用jdbcTemplate.queryForList(myStoredProc, new Object[]{parameters}只从结果中获取第一个表。

我的数据库是SQL Server 2005。

除了jdbcTemplate之外,还有其他方法可以满足我的要求。 如果是,请告诉我。

提前致谢….

见http://static.springsource.org/spring/docs/2.0.7/reference/jdbc.html#jdbc-StoredProcedure

本节中给出的示例完全适用于存储过程返回多个结果集的情况。 虽然给出的示例是针对Oracle的,但它也应该以相同的方式为MS SQL Server工作。

引用sinha的解决方案对我不起作用。 我能够使用JdbcTemplate#call(CallableStatementCreator, List)来解决这个问题。 例如:

 private static final String sql = "{call schema_name.the_stored_procedure(?, ?, ?)}"; // The input parameters of the stored procedure private static final List declaredParams = Arrays.asList( new SqlParameter("nameOfFirstInputParam", Types.VARCHAR), new SqlParameter("nameOfSecondInputParam", Types.VARCHAR), new SqlParameter("nameOfThirdInputParam", Types.VARCHAR)); private static final CallableStatementCreatorFactory cscFactory = new CallableStatementCreatorFactory(sql, declaredParams); // The result sets of the stored procedure private static final List returnedParams = Arrays.asList( new SqlReturnResultSet("nameOfFirstResultSet", SomeRowMapper.INSTANCE), new SqlReturnResultSet("nameOfSecondResultSet", SomeOtherRowMapper.INSTANCE)); public static Map call(JdbcTemplate jdbcTemplate, String param0, String param1, String param2) { final Map actualParams = new HashMap<>(); actualParams.put("nameOfFirstInputParam", param0); actualParams.put("nameOfSecondInputParam", param1); actualParams.put("nameOfThirdInputParam", param2); CallableStatementCreator csc = cscFactory.newCallableStatementCreator(actualParams); Map results = jdbcTemplate.call(csc, returnedParams); // The returned map will including a mapping for each result set. // // { // "nameOfFirstResultSet" -> List // "nameOfSecondResultSet" -> List // } // // For this example, we just return the heterogeneous map. In practice, // it's better to return an object with more type information. In other // words, don't make client code cast the result set lists. Encapsulate // that casting within this method. return results; }