public List executeProcedureWithResultSet(String procedureName,
final Object[] args) {
if (StringUtils.isBlank(procedureName))
return null;
StringBuffer callBuf = new StringBuffer();
callBuf.append("{call ");
callBuf.append(procedureName);
callBuf.append("(");
if (args != null) {
// 循环增加参数
for (int i = 0; i < args.length; i++) {
if (i == (args.length - 1))
callBuf.append("?");
else
callBuf.append("?,");
}
}
callBuf.append(")}");
return (List) getJdbcTemplate().execute(callBuf.toString(),
new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
if (args != null) {
// 设置参数
for (int i = 0; i < args.length; i++) {
cs.setObject(i + 1, args[i]);
}
}
cs.execute();
ResultSet rs = cs.getResultSet();
List retList = ConvertUtil.convertResultSetToList(rs);
return retList;
}
});
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/106285/viewspace-896788/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/106285/viewspace-896788/