執行Sybase儲存過程並返回ResultSet

zenzuguo發表於2007-02-02

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;
}
});
}

[@more@]執行

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/106285/viewspace-896788/,如需轉載,請註明出處,否則將追究法律責任。

相關文章