create proc procName
as
begin
select * from emp
select * from usersso
end
public static Map<String,Object>getAll() throws Exception{
Connection conn=null;CallableStatement cs=null;
ResultSet rs=null;
Map<String,Object> map=new HashMap<String, Object>();
Map<String,String> temp=null;
List<Map<String,String>> list=null;
conn = JdbcUtil.getConn();
cs=conn.prepareCall("{call procName()}");
cs.execute();
rs=cs.getResultSet();
if(rs!=null){
list=new ArrayList<Map<String,String>>();
while(rs.next()){
temp=new HashMap<String, String>();
temp.put("id", rs.getInt("id")+"");
temp.put("name", rs.getString("name")+"");
list.add(temp);
}
map.put("emp", list);
System.out.println(list+"0000");
if(cs.getMoreResults()){
rs=cs.getResultSet();
list=new ArrayList<Map<String,String>>();
while(rs.next()){
temp=new HashMap<String, String>();
temp.put("id", rs.getInt("id")+"");
list.add(temp);
}
map.put("usersso", list);
}
}
System.out.println(JSON.toJSON(map));
return map;
}
本文介绍了一个使用存储过程从两个不同表中获取数据并处理结果集的方法。通过Java代码示例展示了如何连接数据库、调用存储过程以及解析返回的结果集。
564

被折叠的 条评论
为什么被折叠?



