存储过程
IF OBJECT_ID('dbo.sp_xx') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.sp_xx
IF OBJECT_ID('dbo.sp_xx') IS NOT NULL
PRINT '<<< FAILED DROPPING PROCEDURE dbo.sp_xx >>>'
ELSE
PRINT '<<< DROPPED PROCEDURE dbo.sp_xx >>>'
END
go
create proc sp_xx ( @userid int)
as
begin
select * from dbo.PF_Account where Id = @userid
end
EXEC sp_xx 1
go
public void aa() {
final List retList = new ArrayList();
Object object = this.getJdbcTemplate().execute(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection arg0) throws SQLException {
CallableStatement cs = arg0.prepareCall("{call sp_xx(?)}");
return cs;
}
}, new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
cs.setInt(1, 1);
cs.execute();
List columns = new ArrayList();
columns.add("Id");
columns.add("Name");
columns.add("Password");
columns.add("Time");
columns.add("State");
ResultSet rs = cs.getResultSet();
// 根据columns
while (rs.next()) {
Map map = new HashMap();
for (int i = 0; i < columns.size(); i++) {
map.put(columns.get(i), rs.getString(i + 1));
}
retList.add(map);
}
return retList;
}
});
Map map = null;
for (int i = 0; i < retList.size(); i++) {
map = (Map) retList.get(i);
System.out.println(map.get("Password"));
}
}