Spring 调用存储过程返回List

ahljxwy 2014-03-05 11:03:17
大家好,我想通过Spring的namedParameterJdbcTemplate.query方式调用存储过程返回一个bean的List,比如我的实体bean叫Tabc,需要传递参数给存储过程,我是新手,请大神写详细点,谢谢!!!!
...全文
324 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
AS_MSDN 2014-03-07
  • 打赏
  • 举报
回复
这个是最基本的,数据库连接接口
Defonds 2014-03-05
  • 打赏
  • 举报
回复
把这个集成进 spring 即可: http://blog.csdn.net/defonds/article/details/4344797
ahljxwy 2014-03-05
  • 打赏
  • 举报
回复
Connection con 是什么啊?
wyx100 2014-03-05
  • 打赏
  • 举报
回复
回复于: 2014-03-05 14:16:30 用 REF_CURSOR: http://blog.csdn.net/defonds/article/details/5945358
咖啡加糖_ 2014-03-05
  • 打赏
  • 举报
回复
网上找来的,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); }
Defonds 2014-03-05
  • 打赏
  • 举报
回复
ahljxwy 2014-03-05
  • 打赏
  • 举报
回复
我想知道用queryforlist怎么写

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧