- Java code
Object[] params; params = new Object[10]; params[0] = var1; params[1] = var2; params[2] = var3; params[3] = var4; params[4] = var5; params[5] = var6; params[6] = var7; params[7] = var8; params[8] = uuid; params[9] = rs; List newList = this.getJdbcTemplate().queryForList("{call " + procedureName + "(?,?,?,?,?,?,?,?,?,?)}", params);
像我这样,第 10 个参数是输出类型的,返回一个游标,能不能这样用啊?
------解决方案--------------------
好像不行吧!!
这个具体可以去看spring的API!
或者谷歌 一大片的!
------解决方案--------------------
- Java code
List csrList = (List) this.getJdbcTemplate().execute( new CallableStatementCreator() { public CallableStatement createCallableStatement( Connection con) throws SQLException { String storedProc = "{call PROCEDURE_NAME (?,?,?,?,?,?,?)}"; CallableStatement cs = con.prepareCall(storedProc); cs.setInt(1, parInt); // 设置输入参数的值 cs.setString(2, parString); cs.registerOutParameter(3, OracleTypes.CURSOR); // 注册输出参数的类型为游标 return cs; } }, new CallableStatementCallback() { public List doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.execute(); List resList = new ArrayList(); ResultSet rs = (ResultSet) cs.getObject(3); // 获取游标一行的值 while (rs.next()) { Map rowMap = new LinkedHashMap(); // 转换每行的返回值到Map中 for (int i=1; i<=rs.getMetaData().getColumnCount(); i++) { String fieldName = rs.getMetaData().getColumnLabel(i); rowMap.put(fieldName, rs.getObject(fieldName)); } resList.add(rowMap); } rs.close(); return resList; } });