【发布时间】:2016-06-03 09:07:36
【问题描述】:
我必须从 java spring 调用存储过程。这些过程没有输入和输出参数。当我使用 SimpleJdbcCall 调用存储过程时,它返回 null 结果。我该如何解决这个问题?谢谢
存储过程
ALTER PROCEDURE "DBA"."Records" ()
RESULT ( Number integer
, Alias varchar(255)
, File varchar(255)
, ConnCount integer
, PageSize integer
, LogName varchar(255)
)
BEGIN
DECLARE dbid integer;
DECLARE local temporary table t_db_info
( Number integer null
, Alias varchar(255) null
, File varchar(255) null
, ConnCount integer null
, PageSize integer null
, LogName varchar(255) null
) on commit delete rows;
set dbid=next_database(null);
lbl: loop
if dbid is null then
leave lbl
end if
;
insert into t_db_info values(
dbid,db_property('Alias',
dbid),db_property('File',
dbid),db_property('ConnCount',
dbid),db_property('PageSize',
dbid),db_property('LogName',
dbid));
set dbid=next_database(dbid)
end loop lbl
;
select * from t_db_info
ORDER BY alias
END
Java 代码
public class Generic <T>{
protected NamedParameterJdbcTemplate namedJdbcTemplate;
protected JdbcTemplate jdbcTemplate;
protected SimpleJdbcCall procReadAllorgs;
public GenericDAO(DataSource ds) {
this.procReadAllorgs = new SimpleJdbcCall(jdbcTemplate)
.withProcedureName("DBA.Records")
.returningResultSet("records",
BeanPropertyRowMapper.newInstance(Records.class));
init();
}
}
DAO Impl class
public class OrganDAOImpl implements Generic <T> {
public List getList() {
Map m = procReadAllorgs.execute(new HashMap<String, Object>(0));
return (List) m.get("records");
}
}
控制器类
@RequestMapping("/org")
public class TestController {
@Autowired
protected OrganDAOImpl organDAOImpl;
@RequestMapping(value = "/sunday", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List getAll() {
logger.debug("calling the controller...");
return OrganDAOImpl.getList();
}
}
模型类
public class Records {
private Integer Number;
private String Alias;
private String File;
private Integer ConnCount;
private Integer PageSize;
private String LogName;
//getter and setter
}
【问题讨论】:
标签: java spring stored-procedures