我正在使用Spring的JdbcTemplate和StoredProcedure类。我无法让存储过程类为我工作。Spring的存储过程 - 从过程返回的结果始终为空
我在oracle数据库上有一个存储过程。它的签名是
CREATE OR REPLACE PROCEDURE PRC_GET_USERS_BY_SECTION
(user_cursor OUT Pkg_Types.cursor_type
, section_option_in IN Varchar2
, section_in IN Varchar2) AS ....
其中
TYPE cursor_type IS REF CURSOR;
我已创建以下存储过程类从Oracle过程
private class MyStoredProcedure extends StoredProcedure
{
public MyStoredProcedure(JdbcTemplate argJdbcTemplate)
{
super(argJdbcTemplate, "PRC_GET_USERS_BY_SECTION");
declareParameter(new SqlOutParameter("output", OracleTypes.CURSOR));
declareParameter(new SqlParameter("input1", Types.VARCHAR));
declareParameter(new SqlParameter("input2", Types.VARCHAR));
compile();
}
public Map<String, Object> execute() {
Map<String, Object> inParams = new HashMap<String, Object>();
inParams.put("input1", "BG");
inParams.put("input2", "FE");
Map output = execute(inParams);
return output;
}
}
我的方法之一调用此获取信息我的DAO类
public List<String> getUserListFromProcedure() throws BatchManagerException
{
MyStoredProcedure sp = new MyStoredProcedure(this.jdbcTemplate);
Map<String, Object> result = new HashMap<String, Object>();
try
{
result = sp.execute();
}
catch(DataAccessException dae)
{
}
System.out.println(result.size());
return null;
}
但是,地图的大小始终为0,因此无法返回。我知道数据库上有符合我输入条件的行。我还有代码工作,它使用java.sql.CallableStatement
与oracle存储过程交互 - 所以过程很好。将OraceleTypes.CURSOR
与Spring的存储过程混合是不对的?我还能使用什么?我也试过SqlReturnResultSet
,那也没用。
嗨,感谢您的反馈。我使用了我的Oracle存储过程。问题出在我声明的输出参数上。以下工作 declareParameter(new SqlOutParameter(“output”,oracle.jdbc.OracleTypes.CURSOR,new RowMapper(){public String mapRow(ResultSet argResults,int argRowNum)throws SQLException {return argResults.getString(1);}}) );这现在正在为我工作。谢谢 – aos 2010-01-28 14:14:03
您应该已经回答了您自己的问题,并将其选为接受的答案。无论如何感谢张贴。 – 2012-09-25 17:22:07