存储过程返回多个结果集处理
2014-12-19 12:36
489 查看
1 public static Map<String,Object> getAll(){ 2 Connection conn=null; 3 CallableStatement cs=null; 4 ResultSet rs=null; 5 Map<String,Object> map=new HashMap<String, Object>(); 6 Map<String,String> temp=null; 7 List<Map<String,String>> list=null; 8 try { 9 conn=DBCon.getInstance(); 10 cs=conn.prepareCall("{call checkAll()}"); 11 cs.execute(); 12 rs=cs.getResultSet(); 13 if(rs!=null){ 14 list=new ArrayList<Map<String,String>>(); 15 while(rs.next()){ 16 temp=new HashMap<String, String>(); 17 temp.put("id", rs.getInt("id")+""); 18 temp.put("birthday", rs.getDate("birthday")+""); 19 temp.put("name", rs.getString("name")+""); 20 temp.put("title", rs.getString("title")+""); 21 list.add(temp); 22 } 23 map.put("teacher", list); 24 if(cs.getMoreResults()){ 25 rs=cs.getResultSet(); 26 list=new ArrayList<Map<String,String>>(); 27 while(rs.next()){ 28 temp=new HashMap<String, String>(); 29 temp.put("id", rs.getInt("id")+""); 30 temp.put("name", rs.getString("name")); 31 temp.put("age", rs.getInt("age")+""); 32 list.add(temp); 33 } 34 map.put("student", list); 35 } 36 } 37 } catch (Exception e) { 38 e.printStackTrace(); 39 } 40 finally{ 41 DbUtils.closeQuietly(conn, cs, rs); 42 } 43 return map; 44 }
若是数据库是SqlServer,存储过程涉及到表的更新(增、删、改)的话会出错,可以在存储过程里面加上一句:set nocount on即可
相关文章推荐
- EF6调用存储过程,返回多个结果集处理
- php调用mysql存储过程返回结果集的处理
- php调用mysql存储过程返回结果集的处理
- SQL server 的存储过程返回结果集很简单
- 一个游标处理有两个结果集的存储过程
- Oracle中返回结果集的存储过程
- 经典代码(二):C链接存储过程并且得到值返回处理
- oracle的存储过程如何返回结果集
- oracle中存储过程调用存储过程(带有返回结果集)
- Oracle和My Sql返回结果集的存储过程
- java调用存储过程时,返回结果不是ResultSet的时候的处理
- Oracle中返回结果集的存储过程
- 存储过程要返回结果集
- JDBC调用返回结果集的存储过程
- Java调用SQL Server存储过程同时返回参数和结果集
- 熬了个通宵,终于把在ASP里调用存储过程不返回结果集的问题解决了。
- JDBC调用返回结果集的存储过程
- Oracle的存储过程返回结果集的简化办法
- SQLServer下 存储过程内 包含事务 及 返回处理是否成功
- IBatis调用ORACLE的存储过程、函数的返回结果集例子