日期:2014-05-16 浏览次数:20515 次
执行存储过程,返回一个游标结果集,并把游标结果集取出来放入一个list中返回
public List getProcedureValues(String procedure, Object[] o) {
List list = new ArrayList();
Connection con = null;
CallableStatement ps = null;
ResultSet rs = null;
try {
con = getSession().connection();
ps = con.prepareCall(procedure);
ps.registerOutParameter(1, OracleTypes.CURSOR);
for(int i = 0; i < o.length; i++) {
if(null == o[i] || "".equals(o[i].toString().trim()) || "*".equals(o[i].toString().trim())) {
ps.setNull(i+2, Types.VARCHAR);
} else {
ps.setObject(i+2, o[i]);
}
}
ps.execute();
rs = (ResultSet) ps.getObject(1);
while(rs.next()) {
Map base = new LinkedHashMap(100);
ResultSetMetaData data = rs.getMetaData();
for(int i = 1; i < (data.getColumnCount()+1); i++) {
String name = data.getColumnName(i);
Object obj = rs.getObject(name);
base.put(name.toLowerCase(), obj!=null?obj:"");
}
list.add(base);
}
rs.close();
ps.close();
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("根据sql查询失败\r\n" + e.getMessage());
}
return list;
}