Mysql利用存储过程获取结果集

来源:互联网 发布:深圳阿里云幕布拍照 编辑:程序博客网 时间:2024/05/18 18:00

1、创建

begin

     select * from yewu_hetong;

end

额外的方案

begin
create temporary table tmp1 like t;
insert into tmp1 select * from t;
create temporary table tmp2 like t;
insert into tmp2 select * from t;
end;

ps.....MySQL只能获取前10个结果集,如果有多余的,请自行用代码获取

2、获取

 con = Mytest.getConn();   //获取连接        String sql = "{call test()}";       cs = con.prepareCall(sql);       boolean hadResults = cs.execute();       int i=0;       while (hadResults) {           System.out.println(++i);           ResultSet rs = cs.getResultSet();           while (rs != null && rs.next()) {              String name= rs.getString(1);              System.out.println(name);           }           hadResults = cs.getMoreResults(); //检查是否存在更多结果集       }



0 0
原创粉丝点击