我想用spring JDBC调用这个语句怎么做
select* from cdc.fn_cdc_get_all_changes_dbo_Student(@from_lsn,@to_lsn,@row_filter_option);
我应该使用JDBCTemplate
class 还是SimpleJdbcCall
class 。
我试过了,但没有奏效:
jdbcTemplate.setResultsMapCaseInsensitive(true);
SimpleJdbcCall mysimpleJdbcCall = new SimpleJdbcCall(jdbcTemplate);
mysimpleJdbcCall.withSchemaName("cdc")
.withProcedureName("fn_cdc_get_all_changes_dbo_student").returningResultSet("students",
new RowMapper<Student>()
{
@Override
public Student mapRow(ResultSet rs, int rowNum) throws SQLException
{
Student s = new Student();
s.setId(rs.getInt(5));
s.setName(rs.getString(6));
s.setAge(rs.getInt(7));
return s;
}
});
MapSqlParameterSource paramSource =new MapSqlParameterSource();
// paramSource.addValue("capture_instance", "dbo_student");
paramSource.addValue("from_lsn", lsn1);
paramSource.addValue("to_lsn", lsn2);
paramSource.addValue("row_filter_option","all");
paramSource.addValue("TABLE_RETURN_VALUE", null);
/* ResultSet rs = mysimpleJdbcCall.executeFunction(ResultSet.class, paramSource);
return null;*/
Map m = mysimpleJdbcCall.execute(paramSource);
List<Student> s= (List)m.get("students");
return s;