mysql 创建存储过程 返回结果集 调用存储过程

来源:互联网 发布:淘宝上卖电子书违法吗 编辑:程序博客网 时间:2024/04/29 13:22
DELIMITER //


CREATE PROCEDURE test_proc_multi_select()  
BEGIN  
         SELECT * FROM testproc;  
         SELECT * FROM testproc WHERE id=1;  

END; 


///////使用方式

  1. con = MConnection.getConn();  
  2.        String sql = "{call test_proc_multi_select()}";  
  3.       cs = con.prepareCall(sql);  
  4.       boolean hadResults = cs.execute();  
  5.       int i=0;  
  6.       while (hadResults) {  
  7.           System.out.println("result No:----"+(++i));  
  8.           ResultSet rs = cs.getResultSet();  
  9.           while (rs != null && rs.next()) {  
  10.              int id1 = rs.getInt(1);  
  11.              String name1 = rs.getString(2);  
  12.              System.out.println(id1 + ":" + name1);  
  13.           }  
  14.           hadResults = cs.getMoreResults(); //检查是否存在更多结果集  
  15.       }  

0 0
原创粉丝点击