CREATE OR REPLACE PROCEDURE TESTPRO(PARAM1 IN VARCHAR2,test_cursor out TESTPACKAGE.TEST_CURSOR) IS
public void test() {
List resultList = (List) jdbcTemplate.execute(
new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con) throws SQLException {
String storedProc = "{call testpro(?,?)}";// 调用的sql
CallableStatement cs = con.prepareCall(storedProc);
cs.setString(1, "p1");// 设置输入参数的值
cs.registerOutParameter(2, OracleTypes.CURSOR);// 注册输出参数的类型
return cs;
}
}, new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement cs) throws SQLException,DataAccessException {
List resultsMap = new ArrayList();
cs.execute();
ResultSet rs = (ResultSet) cs.getObject(2);// 获取游标一行的值
while (rs.next()) {// 转换每行的返回值到Map中
Map rowMap = new HashMap();
rowMap.put("id", rs.getString("id"));
rowMap.put("name", rs.getString("name"));
resultsMap.add(rowMap);
}
rs.close();
return resultsMap;
}
});
for (int i = 0; i < resultList.size(); i++) {
Map rowMap = (Map) resultList.get(i);
String id = rowMap.get("id").toString();
String name = rowMap.get("name").toString();
System.out.println("id=" + id + ";name=" + name);
}
}